Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Lec10.cpp
- #include <iostream>
- #include <iomanip>
- using namespace std;
- enum statements { InsertMoney, WaitForSelection, CheckInventory, ReturnTotal };
- double sodacost = 0.75;
- statements state = InsertMoney;
- int main()
- {
- int coke = 2;
- int pepsi = 2;
- while (true) {
- switch (state) {
- case InsertMoney:
- cout << "Please Insert Money or press 0 for a refund" << endl;
- double money;
- cin >> money;
- if (money == 0) {
- state = ReturnTotal;
- }
- else if (money >= sodacost) {
- double change = money - sodacost;
- cout << "Your change is " << change << endl;
- state = WaitForSelection;
- }
- else if (money < sodacost) {
- cout << "Not enough money" << endl;
- state = InsertMoney;
- }
- break;
- case WaitForSelection:
- cout << "Please press 1 for Coke, 2 for Pepsi, or 9 for refund: " << endl;
- int decision;
- cin >> decision;
- if (decision == 1) {
- state = CheckInventory;
- }
- else if (decision == 2) {
- state = CheckInventory;
- }
- else if (decision == 9) {
- state = ReturnTotal;
- }
- break;
- case CheckInventory:
- cout << "The inventory is currently being checked. Please wait a moment" << endl;
- if (decision == 1) {
- if (coke > 0) {
- coke--;
- cout << "Please enjoy your Coke. I wish I could drink soda" << endl;
- state = InsertMoney;
- }
- else if (coke == 0) {
- cout << "We are all sold out of Coke. Sorry" << endl;
- state = ReturnTotal;
- }
- }
- else if (decision == 2) {
- if (pepsi > 0) {
- pepsi--;
- cout << "Please enjoy your Pepsi. It's not like I wanted some Pepsi" << endl;
- state = InsertMoney;
- }
- else if (pepsi == 0) {
- cout << "We are all sold out of Pepsi. Sorry" << endl;
- state = ReturnTotal;
- }
- }
- break;
- case ReturnTotal:
- cout << "Your return is: $" << money << endl;
- state = InsertMoney;
- break;
- }
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement