You are on page 1of 2

#include <iostream> using namespace std; int main(){ char start; double money = 5.00; double watercost = .

75; double sodacost = 1.00; double twixcost = .80; double snickerscost = .90; double chipscost = 1.00; bool exit; cout << "Welcome to the vending machine." << endl; cout << "You start with $5.00 in your wallet." << endl; cout << "Press any key to start..." << endl; cin >> start; do { system("cls"); int choice; cout << "What would you like to do?" << endl; cout << "(1)Purchase\n(2)Check wallet\n(3)Exit" << endl; cin >> choice; system("cls"); if (choice == 1) { int snack; cout << "The available items are: " << endl; cout << "(1)Water - $.75\n(2)Soda - $1.00\n(3)Twix - $.80\n(4)Snicker s - $.90\n(5)Chips - 1.00" << endl; cin >> snack; system("cls"); if (snack == 1 && money >= .75) { cout << "You buy the water for $.75" << endl; money -= watercost; exit = false; } else if (snack == 1 && money < .75) { cout << "You don't have enough money for that!" << endl; exit = false; } else if (snack == 2 && money >= 1.00) { cout << "You buy the soda for $1.00" << endl; money -= sodacost; exit = false; } else if (snack == 2 && money < 1.00) { cout << "You don't have enough money for that!" << endl; exit = false; } else if (snack == 3 && money >= .80) { cout << "You buy the twix for $.80" << endl; money -= twixcost; exit = false; } else if (snack == 3 && money < .80) { cout << "You don't have enough money for that!" << endl; exit = false; } else if (snack == 4 && money >= .90) {

cout << "You buy the snickers for $.90" << endl; money -= snickerscost; exit = false; } else if (snack == 4 && money < .90) { cout << "You don't have enough money for that!" << endl; exit = false; } else if (snack == 5 && money >= 1.00) { cout << "You buy the twix for $1.00" << endl; money -= chipscost; exit = false; } else if (snack == 5 && money < 1.00) { cout << "You don't have enough money for that!" << endl; exit = false; } else { cout << "Invalid choice. Try again." << endl; exit = false; } } else if (choice == 2) { cout << "You have $" << money << " in your wallet." << endl; exit = false; } else if (choice == 3) { cout << "Goodbye." << endl; exit = true; } else { cout << "Invalid choice. Try again." << endl; exit = false; } } while (!exit); system("pause"); return 0; }

You might also like