How would I prompt the user to give them the option to rerun program in C++ -
the option like: "to run program again enter 'y', exit enter 'n'. in program ask user enter package a,b, or c. calculate price based on different factors. have give user option select package rerun entire program?
#include <iostream> using namespace std; int main() { bool finished = false; char choice; int choice_a = 995; int choice_b = 1995; int choice_c = 3995; int message_units; int price; bool selected = false; { { //prompt user enter package cout << "which package choose (enter a, b or c)" << endl; cin >> choice; if (choice == 'a') { price = choice_a; selected = true; } else if (choice == 'b') { price = choice_b; selected = true; } else if (choice == 'c') { price = choice_c; selected = true; } cout << endl; } while (selected == false); //prompt user enter message units cout << "how many message units (enter 1 - 672)" << endl; cin >> message_units; //calculate message units if((message_units > 5) && (choice == 'a')){ price += 100 * (message_units - 5); } if((message_units > 15) && (choice == 'b')){ price += 50 * (message_units - 15); } //total cost cout << "your total cost " << price/100 << "." << price%100 <<
#include <iostream> using namespace std; int main() { bool finished = false; char choice; int choice_a = 995; int choice_b = 1995; int choice_c = 3995; int message_units; int price; bool selected = false; char rerunp; rerunprog: { { //prompt user enter package cout << "which package choose (enter a, b or c)" << endl; cin >> choice; if (choice == 'a') { price = choice_a; selected = true; } else if (choice == 'b') { price = choice_b; selected = true; } else if (choice == 'c') { price = choice_c; selected = true; } cout << endl; } while (selected == false); //prompt user enter message units cout << "how many message units (enter 1 - 672)" << endl; cin >> message_units; //calculate message units if((message_units > 5) && (choice == 'a')){ price += 100 * (message_units - 5); } if((message_units > 15) && (choice == 'b')){ price += 50 * (message_units - 15); } cout<<"do want run again?(y/n)"; cin >> rerunp; while(rerunp == 'y') goto rerunprog; //total cost cout << "your total cost " << price/100 << "." << price%100 << ; cout<<"do want run again?(y/n)"; cin >> rerunp; while(rerunp == 'y') goto rerunprog;
Comments
Post a Comment