Getting switch to loop in C++ -
i trying finish assignment c++ class , stuck. not sure if approaching problem correctly. trying create menu based programme add together items 'cart' based on user's menu selection , allow user increment how many tickets have in 'cart'.
then if press n, go main menu , when press 5 'checkout' give them total of order.
any help appreciated.
thank you
#include <iostream> using namespace std; int main() { char menuopt; int total = 0; char moretix; cout << "use menu options 1-5 add together ticket cart." << endl; cout << "option 1: adult - airboat ride & alligator wrestling show.\n"; cout << "\t price: $10" << endl; cout << "option 2: adult - airboat ride, alligator wrestling show & photo wrestler.\n"; cout << "\t price: $15" << endl; cout << "option 3: senior - airboat ride & alligator wrestling show.\n"; cout << "\t price: $7" << endl; cout << "option 4: kid - airboat ride, alligator wrestling show & stuffed toy alligator.\n"; cout << "\t price: $10" << endl; cout << "option 5: checkout" cout << "option: "; cin >> menuopt; do{ switch(menuopt){ case '1': cout << "adult airboat ride & alligator wrestling show has been added cart." << endl; total += 10; break; case '2': cout << "adult airboat ride, alligator wrestling show & photo wrestler has been added cart." << endl; total += 15; break; case '3': cout << "senior airboat ride & alligator wrestling show has been added cart." << endl; total += 7; break; case '4': cout << "child airboat ride, alligator wrestling show & stuffed toy alligator has been added cart." << endl; total +=10; break; case '5': cout << "the total purchase $" << total << endl; default: cout << "you have made invalid choice. please create selection." << endl; } cout << "would purchase ticket? (y/n) "; cin >> moretix; }while (moretix == 'y' || moretix == 'y'); homecoming 0; }
if understand question correctly, not able see menu 1 time user chooses purchase more tickets.
put do
statement above line , should work:
cout << "use menu options 1-5 add together ticket cart." << endl;
c++ loops switch-statement do-while
No comments:
Post a Comment