English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

F'Zone offers three different types of burgers to hungry students in Fairmont. You have to write a small program in C++ to calculate the price of a burger order. Your program should display the following menu to the user and prompts for his/her choice:



1: Quarter pounder combo

2: Bacon burger

3: Swiss mushroom burger


· If the user enters 1, then the program should ask the user if he wants the “biggy” size and if he wants to add cheese. The combo costs $4.59; “biggy” size costs $.39 more, and cheese costs $.25 more.

· If the user enters 2, then the program should ask the user if he wants to add cheese and fries. The burger costs $3.49; fries costs $.59 more, and cheese costs $.25 more.

· If the user enters 3, then the program should ask the user if he wants to add onion rings and a coke. The burger costs $4.99; onions rings costs $.79 more, and coke costs $.75 more.

· If the user enters anything else, the program should display an error message and terminate.



For the YES/NO answers, the user should enter an upper case 'Y' or 'N'. All prices include tax. Finally, the total of the order should be calculated and displayed in dollars and cents. The input/output of the program should strictly follow the format shown in the sample executions.


For character input, you should use the getchar function. Following is an example of how you can use this:

char x;
x = getchar();

2006-11-05 16:34:49 · 3 answers · asked by rh138 1 in Computers & Internet Programming & Design

3 answers

#include
#include

using namespace std;

int main() {

  cout << "Welcome to F\'Zone\n"
      << "\n"
      << "Please select from the following menu.\n"
      << "\n"
      << "1: Quarter pounder combo\n"
      << "\n"
      << "2: Bacon burger\n"
      << "\n"
      << "3: Swiss mushroom burger\n"
      << "\n"
      << "To place your order, enter the number of the meal you would like.\n"
      << "For instance enter 2 for a Bacon Burger.\n"
      << "\n"
      << "Please enter your selection now: ";
  char x;
  x = getchar();
  double total = 0.0;
  switch (x) {
    case '1' :
      total = 4.59;
      cout << "Would you like a \'biggy\' size? It costs $0.39 extra.\n"
          << "Type in a 'Y' or a 'N': ";
      //x = getchar();
      cin >> x;
      if (x == 'Y') {
        total += 0.39;
        cout << "You have chosen to have a \'biggy\' size.\n";
      }
      cout << "Would you like cheese with that? It costs $0.25 extra.\n"
          << "Type in a 'Y' or a 'N': ";
      //x = getchar();
      cin >> x;
      if (x == 'Y') {
        total += 0.25;
        cout << "You have chosen to have cheese.\n";
      }
      break;
    case '2' :
      // similar to 1, just change the price and messages.
      break;
    case '3' :
      // similar to 1, just change the price and messages.
      break;
    default :
      cout << "You have not ordered a menu item.";
      return 1;
  }
  cout << "The total of your order is $" << setiosflags(ios::fixed)
      << setprecision(2) << total << resetiosflags(ios::fixed);
}

2006-11-07 00:54:07 · answer #1 · answered by Mark aka jack573 7 · 0 0

Which class is this from? I would be interested in taking it.

Please do your own homework. It will really pay off in the end.

2006-11-06 00:53:16 · answer #2 · answered by RGB_Mars 3 · 1 0

So basically you don't want help, that is to learn. You just want someone to do your assignment for you, so you learn nothing. Here is your program.

#include
#include

using namespace std;

int main()
{
string question;

question = "no sense";

if (question == "sense")
{
cout << "You rox my lvl 27 sox!";
}
else
{
cout << "You seriously suck at asking questions" << endl;
cout << "Try doing your own work, or at least thinking about it before you ask" << endl;
cout << "WTF PWNED!!!" << endl;
}
return 0;
}

2006-11-06 01:52:14 · answer #3 · answered by D 4 · 0 0

fedest.com, questions and answers