restaurant bill

whenever I try to build my program it keeps failing because "Redefinition of 'MealCost_tax'". Can someone please help me

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
#include <iostream>
#include <string> 
using namespace std;

int main ()
{
    string RestaurantBill;
    
    // variable declaration
    double
    MealCost = 50.00,
    tax = .0675,
    tip = .1,
    tipp = .15,
    tippp = .2;
    int
    MealCost_tax,
    bill,
    TotalBill,
    tip_TotalBill,
    
    // calculate tax of meal cost
    MealCost_tax = MealCost * tax;
    
    // calculate bill amount
    bill = MealCost_tax + MealCost;
    
    //calculate tip with 10% tax
    tip = MealCost * tip ;
    
    //calculate tip with 15% tax
    tipp = MealCost * tipp ;
    
    //calculate tip with 20% tax
    tippp = MealCost * tippp ;
    
    //calculate the total bill
    cout << "The Total is $" << MealCost << " w/o tax" << endl;
    cout << "tax amount is $" << MealCost_tax << endl;
    cout << "bill amount with 10% tip is $ " << TotalBill + tip << endl;
    cout << "bill amount with 15% tip is $ " << TotalBill + tipp << endl;
    cout << "bill amount with 20% tip is $ " << TotalBill + tippp << endl;
    system("pause");
    return 0;
}
@cm123

On line 20, try replacing the comma with a semicolon. With the comma there, MealCost_tax is being viewed as another variable.
Look at line 20:

tip_TotalBill,

It should be followed by a semi-colon (;), not a comma (,). Since the comma is there, the compiler expects another identifier.

Some other things:

Your variable bill (declared on line 18) is set on line 26, but it is unused.
Your variable tip_TotalBill (declared on line 20) is unused.
Your variable TotalBill (declared on line 19) is uninitialized. You never give it a value. You then attempt to use it on lines 40 - 42.
Last edited on
Topic archived. No new replies allowed.