1

Hi Folks,

Total C++ newbie here so please excuse my errors! I have been tasked with writing a small program and I can't get it to work. Here is the task description...

"A restaurant has 4 lunch combos for customers to choose:

Combo A : Fried chicken with slaw [price: 4.25]
Combo B : roast beef with mashed potato [price: 5.75]
Combo C : Fish and chips [price:5.25]
Combo D : soup and salad [price: 3.75]

Write a program to calculate how much a party of customers should pay. Suppose the party orders 2 B’s, 1 A and 3 D’s. The casher will enter B, B, A, D, D, D and T into the program. The T means “calculating total of the order”. It is a signal telling the computer that the whole order has been entered and it is time to calculate the total amount the party should pay. Assume there is no sales tax. "

I am supposed to try using while loops and switch for this task. I've been tinkering with this and some of this works but some doesn't. For example, when I enter T to calculate the Total I get nothing returned and the program ends. Same thing happens when I enter option C. I suspect that at least part of the problem is my break statements but any advice is GREATLY appreciated. When the program gets to 'break;' does it go back to 'switch' or somewhere else? Many Thanks!

Here's my totally newbie code ...

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main( )
{
   char item = ' ';
	double subTotalA = 0;
    double subTotalB = 0;
	double subTotalC = 0;
	double subTotalD = 0;
	double total = 0;

	cout << "Enter the combo ordered [A/B/C/D] or T to calculate total: ";
	cin >> item;
	item = toupper(item);

	switch (item)
	{
                 
                    case 'A': while (item == 'A')
	     {
	            subTotalA = subTotalA + 4.25;
		
	            cout << "Enter the next item ordered [A/B/C/D] or T to calculate the Total. "; 
	            cin >> item;
	            item = toupper(item);
                							
	      }
	     break;
            		
	     case 'B': while (item == 'B')
	      {
		subTotalB = subTotalB + 5.75;
	
                                cout << "Enter the next item ordered [A/B/C/D] or T to calculate the Total. "; 
		cin >> item;
                                item = toupper(item);							
                      }
	       break;
		
	      case 'C': while (item == 'C')
	       {
		subTotalC = subTotalC + 5.25;
	
                                cout << "Enter the next item ordered [A/B/C/D] or T to calculate the Total. "; 
		cin >> item;
		item = toupper(item);
								
	        }
	        break;
		
	      case 'D': while (item == 'D')
                       {
		subTotalD = subTotalD + 4.25;
	
		cout << "Enter the next item ordered [A/B/C/D] or T to calculate the Total. "; 
		cin >> item;
		item = toupper(item);
				
                        }
	        break;
		 
	     case 'T': while (item == 'T')
	        {
	            total = subTotalA + subTotalB + subTotalC + subTotalD;
	            cout << "The Total is: $" << total << endl;
	        
	        }
                        break;
                   
      }	


system("pause");
return 0;

}
Votes + Comments
thanks for using code tags right
1
Contributor
1
Reply
3
Views
10 Years
Discussion Span
Last Post by Tyster
0

Nevermind everyone! I got this one firgured out!

Thanks for looking!

Tyster

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.