HELP!

A restaurant has 3 lunch combos for customers to choose:
Combo A: Fried chicken with coleslaw [price: 6.00]
Combo B: Roast beef with mashed potato [price: 6.25]
Combo C: Fish and chips [price: 5.75]

Write a program to calculate how much a group of customers should pay. The program first asks how many customers there are in the group. Then it asks the combo ordered by each customer. If case a customer does not want to order anything, the cashier will enter X, which means order nothing, into the program. When every customer in the group has placed his/her order, the program will display the number of each combo ordered and the total amount of this group’s bill.

Here is my code. I am failing miserably.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
using namespace std;

int main()
{
int customers = 0;
char combo = ' ';

int comboA = 0;
double comboAprice = 0.0;
int comboB = 0;
double comboBprice = 0.0;
int comboC = 0;
double comboCprice = 0.0;
int comboX = 0;
double comboXprice = 0.0;
double aDue = 0.0;

cout << "How many customers are in your group? ";
cin >> customers;

for (int counter = customers; counter = customers; counter = customers)
{
    cout << "What combo would you like (A,B,C)? ";
    cin >> combo;
    combo = toupper(combo);
    switch (combo)
    {
           case 'A' : comboA = comboA + 1;
                      comboAprice = comboA * 6.00;
                break;
           case 'B' : comboB = comboB + 1;
                      comboBprice = comboB * 6.25;
                break;
           case 'C' : comboC = comboC + 1;
                      comboCprice = comboC * 5.75;
                break;
           case 'X' : comboX = comboX + 1;
                      comboXprice = comboX * 0.00;
    }
}
aDue = comboAprice + comboBprice + comboCprice;
cout << "Number of Combo A order: " << comboA << endl;
cout << "Number of Combo B order: " << comboB << endl;
cout << "Number of Combo C order: " << comboC << endl;
cout << "Total amount due: " << aDue << endl;

system ("pause");
return 0;
    
}
Last edited on
On line 22, your for loop syntax is incorrect.
For loops follow the pattern for(variable, condition, increment).
Your variable, counter, should begin at 0.
Your loop should continue while counter is less than customers; loop once per customer.
Your increment is simply adding one to counter.

That said, your for loop should look like this:
1
2
3
4
for(int counter = 0; counter < customers; ++counter) 
{ //loop until counter >= customers, and increment counter each loop
 //....
}


You can read more about for loops here:
http://www.cplusplus.com/doc/tutorial/control/
Thank you. I feel like an idiot. It works now.
Topic archived. No new replies allowed.