gas lab

Problems with illegal cases

#include < iostream>

# include <iomanip>

using namespace std;


double REGULAR_RATE = 3.899;
double MID_RATE = 3.999;
double PREMIUM_RATE = 4.199;
double DIESEL_RATE = 4.199;
double ULTRA_WASH = 9.000;
double SUPER_WASH = 7.000;
double REGULAR_WASH = 5.000;
double _DISCOUNT = 3.000;
double DISCOUNT_ = 1.500;
const char Yes = 1;
const char No = 2;
int main()

{
// variable declarations
double price_of_gas, number_of_gallons, wash_cost = 0;
int gas_type, car_wash_type, ans = 0;

// user input

cout<<"Welcome to MSU's Gas 'N' Go!"<<endl<<endl;
cout<<"This program allows users to calculate the price by entering the Type of gas and the number of Gallons.";
cout<<"It also offers the users a discounted car wash with the purchase of 5 or more gallons.";
cout<<"What type of gas would you like to purchase today?"<< endl;
cout << "Please enter 1 for Regular, 2 for Mid Grade, 3 for Premium, or 4 for Diesel."<<endl<<endl;
cin>>gas_type;
cout<<"Now, enter the number of gallons" << endl;
cin>>number_of_gallons;

if(number_of_gallons >=10);
{
cout<<"We also give a $3.00 discount with any purchase of 10 or more gallons, and a $1.50 for 5 or more gallons"<<endl <<endl;
cout<<"Enter 1 to include the car wash of 2 to cancel the car wash." << endl;
cin>>ans;

if (ans==Yes);

{
cout << "Please enter 1 for Ultra wash = $ 9.00, 2 Super wash = $7.00 ,3 for Regular wash= $ 5.00.";
cin >> car_wash_type;
}
switch( gas_type);
{

case 1:
price_of_gas = number_of_gallons * REGULAR_RATE;
cout << "The type of gas you selected is REGULAR." << endl;
cout << "The cost of your gas is $"<<price_of_gas << endl;


case 2:
price_of_gas = number_of_gallons * MID_RATE;
cout << "The type of gas you selected is MID GRADE." << endl;
cout << "The cost of your gas is $"<<price_of_gas << endl;


case 3:
price_of_gas = number_of_gallons * PREMIUM_RATE;
cout << "The type of gas you selected is PREMIUM." << endl;
cout << "The cost of your gas is $"<<price_of_gas << endl;


case 4:
price_of_gas = number_of_gallons * DIESEL_RATE;
cout << "The type of gas you selected is DIESEL." << endl;
cout << "The cost of your gas is $"<<price_of_gas << endl;

default: cout<< " Thank You For Shopping by at MSU's Gas and GO!" <<endl;
}


switch( car_wash_type);
{

case 1:
wash_cost = ULTRA_WASH - _DISCOUNT;
cout << "The type of car wash you selected is ULTRA WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost << endl;


case 2:
wash_cost = SUPER_WASH - _DISCOUNT;
cout<< "The type of car wash you selected is SUPER WASH." << endl;
cout<< "The cost of your car wash is $"<< wash_cost<< endl;


case 3:
wash_cost = REGULAR_WASH - _DISCOUNT;
cout<<"The type of gas you selected is REGULAR WASH."<<endl;
cout<<"The cost of your car wash is $"<< wash_cost<<endl;

default: cout<<"Thank You For Shopping by at MSU's Gas and GO!"<<endl;
}

}
}
}
if (number_of_gallons==5);
{
cout<<"We also give a $1.50 discount with any purchase of 5 or more gallons."<<endl <<endl;
cout<<"Enter 1 to include the car wash of 2 to cancel the car wash." << endl;
cin>>ans;

case 1:
wash_cost = ULTRA_WASH - DISCOUNT_;
cout << "The type of car wash you selected is ULTRA WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost << endl;


case 2:
wash_cost = SUPER_WASH - DISCOUNT_;
cout << "The type of car wash you selected is SUPER WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost<< endl;


case 3:
wash_cost = REGULAR_WASH - DISCOUNT_;
cout << "The type of gas you selected is REGULAR WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost << endl;


case 0: cout<< " Thank You For Shopping by at MSU's Gas and GO!" <<endl;
}

else if (number_of_gallons==6);
{

case 1:
wash_cost = ULTRA_WASH - DISCOUNT_;
cout << "The type of car wash you selected is ULTRA WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost << endl;


case 2:
wash_cost = SUPER_WASH - DISCOUNT_;
cout << "The type of car wash you selected is SUPER WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost<< endl;


case 3:
wash_cost = REGULAR_WASH - DISCOUNT_;
cout << "The type of gas you selected is REGULAR WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost << endl;


case 0: cout<< " Thank You For Shopping by at MSU's Gas and GO!" <<endl;

}
else if (number_of_gallons==7);
{

case 1:
wash_cost = ULTRA_WASH - DISCOUNT_;
cout << "The type of car wash you selected is ULTRA WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost << endl;


case 2:
wash_cost = SUPER_WASH - DISCOUNT_;
cout << "The type of car wash you selected is SUPER WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost<< endl;


case 3:
wash_cost = REGULAR_WASH - DISCOUNT_;
cout << "The type of gas you selected is REGULAR WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost << endl;


case 0: cout<< " Thank You For Shopping by at MSU's Gas and GO!" <<endl;
}
else if (number_of_gallons==8);
{

case 1:
wash_cost = ULTRA_WASH - DISCOUNT_;
cout << "The type of car wash you selected is ULTRA WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost << endl;


case 2:
wash_cost = SUPER_WASH - DISCOUNT_;
cout << "The type of car wash you selected is SUPER WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost<< endl;


case 3:
wash_cost = REGULAR_WASH - DISCOUNT_;
cout << "The type of gas you selected is REGULAR WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost << endl;


case 0: cout<< " Thank You For Shopping by at MSU's Gas and GO!" <<endl;
}
else (number_of_gallons==9);
{

case 1:
wash_cost = ULTRA_WASH - DISCOUNT_;
cout << "The type of car wash you selected is ULTRA WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost << endl;


case 2:
wash_cost = SUPER_WASH - DISCOUNT_;
cout << "The type of car wash you selected is SUPER WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost<< endl;


case 3:
wash_cost = REGULAR_WASH - DISCOUNT_;
cout << "The type of gas you selected is REGULAR WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost << endl;


case 0: cout<< " Thank You For Shopping by at MSU's Gas and GO!" <<endl;
}

system ("PAUSE");

return 0;
}
You have quite a few semi-colons that need to be removed. You can't just slap one after every line.

1
2
3
4
5
if (ans==Yes);
{
    cout << "Please enter 1 for Ultra wash = $ 9.00, 2 Super wash = $7.00 ,3 for Regular wash= $ 5.00.";
    cin >> car_wash_type;
}


is the same as:

1
2
3
4
5
6
7
if (ans==Yes)
    /* empty statement */ ;

{
    cout << "Please enter 1 for Ultra wash = $ 9.00, 2 Super wash = $7.00 ,3 for Regular wash= $ 5.00.";
    cin >> car_wash_type;
}


The same applies to your switch statements.
Last edited on
like where?
See the edited post above.
thanks!
that helped, but im still getting errors such as missing function header, etc.
here's the slightly edited program, by the way

#include < iostream>

# include <iomanip>

using namespace std;


double REGULAR_RATE = 3.899;
double MID_RATE = 3.999;
double PREMIUM_RATE = 4.199;
double DIESEL_RATE = 4.199;
double ULTRA_WASH = 9.000;
double SUPER_WASH = 7.000;
double REGULAR_WASH = 5.000;
double _DISCOUNT = 3.000;
double DISCOUNT_ = 1.500;
const char Yes = 1;
const char No = 2;
int main()

{
// variable declarations
double price_of_gas, number_of_gallons, wash_cost = 0;
int gas_type, car_wash_type, ans = 0;

// user input

cout<<"Welcome to MSU's Gas 'N' Go!"<<endl<<endl;
cout<<"This program allows users to calculate the price by entering the Type of gas and the number of Gallons.";
cout<<"It also offers the users a discounted car wash with the purchase of 5 or more gallons.";
cout<<"What type of gas would you like to purchase today?"<< endl;
cout << "Please enter 1 for Regular, 2 for Mid Grade, 3 for Premium, or 4 for Diesel."<<endl<<endl;
cin>>gas_type;
cout<<"Now, enter the number of gallons" << endl;
cin>>number_of_gallons;

if(number_of_gallons >=10)
{
cout<<"We also give a $3.00 discount with any purchase of 10 or more gallons, and a $1.50 for 5 or more gallons"<<endl <<endl;
cout<<"Enter 1 to include the car wash of 2 to cancel the car wash." << endl;
cin>>ans;

if (ans==Yes)

{
cout << "Please enter 1 for Ultra wash = $ 9.00, 2 Super wash = $7.00 ,3 for Regular wash= $ 5.00.";
cin >> car_wash_type;
}
switch( gas_type)
{

case '1':
price_of_gas = number_of_gallons * REGULAR_RATE;
cout << "The type of gas you selected is REGULAR." << endl;
cout << "The cost of your gas is $"<<price_of_gas << endl;
return 0;

case 2:
price_of_gas = number_of_gallons * MID_RATE;
cout << "The type of gas you selected is MID GRADE." << endl;
cout << "The cost of your gas is $"<<price_of_gas << endl;


case 3:
price_of_gas = number_of_gallons * PREMIUM_RATE;
cout << "The type of gas you selected is PREMIUM." << endl;
cout << "The cost of your gas is $"<<price_of_gas << endl;


case 4:
price_of_gas = number_of_gallons * DIESEL_RATE;
cout << "The type of gas you selected is DIESEL." << endl;
cout << "The cost of your gas is $"<<price_of_gas << endl;

default: cout<< " Thank You For Shopping by at MSU's Gas and GO!" <<endl;
}


switch( car_wash_type)
{

case 1:
wash_cost = ULTRA_WASH - _DISCOUNT;
cout << "The type of car wash you selected is ULTRA WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost << endl;


case 2:
wash_cost = SUPER_WASH - _DISCOUNT;
cout<< "The type of car wash you selected is SUPER WASH." << endl;
cout<< "The cost of your car wash is $"<< wash_cost<< endl;


case 3:
wash_cost = REGULAR_WASH - _DISCOUNT;
cout<<"The type of gas you selected is REGULAR WASH."<<endl;
cout<<"The cost of your car wash is $"<< wash_cost<<endl;

default: cout<<"Thank You For Shopping by at MSU's Gas and GO!"<<endl;
}

}

}
else (number_of_gallons==5,6,7,8,9);
{
cout<<"We also give a $1.50 discount with any purchase of 5 or more gallons."<<endl <<endl;
cout<<"Enter 1 to include the car wash of 2 to cancel the car wash." << endl;
cin>>ans;

case 1:
wash_cost = ULTRA_WASH - DISCOUNT_;
cout << "The type of car wash you selected is ULTRA WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost << endl;


case 2:
wash_cost = SUPER_WASH - DISCOUNT_;
cout << "The type of car wash you selected is SUPER WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost<< endl;


case 3:
wash_cost = REGULAR_WASH - DISCOUNT_;
cout << "The type of gas you selected is REGULAR WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost << endl;


case 0: cout<< " Thank You For Shopping by at MSU's Gas and GO!" <<endl;
}




system ("PAUSE");

return 0;
}
further modified

#include < iostream>

# include <iomanip>

using namespace std;


double REGULAR_RATE = 3.899;
double MID_RATE = 3.999;
double PREMIUM_RATE = 4.199;
double DIESEL_RATE = 4.199;
double ULTRA_WASH = 9.000;
double SUPER_WASH = 7.000;
double REGULAR_WASH = 5.000;
double _DISCOUNT = 3.000;
double DISCOUNT_ = 1.500;
const char Yes = 1;
const char No = 2;
int main()

{
// variable declarations
double price_of_gas, number_of_gallons, wash_cost = 0;
int gas_type, car_wash_type, ans = 0;

// user input

cout<<"Welcome to MSU's Gas 'N' Go!"<<endl<<endl;
cout<<"This program allows users to calculate the price by entering the Type of gas and the number of Gallons.";
cout<<"It also offers the users a discounted car wash with the purchase of 5 or more gallons.";
cout<<"What type of gas would you like to purchase today?"<< endl;
cout << "Please enter 1 for Regular, 2 for Mid Grade, 3 for Premium, or 4 for Diesel."<<endl<<endl;
cin>>gas_type;
cout<<"Now, enter the number of gallons" << endl;
cin>>number_of_gallons;

if(number_of_gallons >=10)
{
cout<<"We also give a $3.00 discount with any purchase of 10 or more gallons, and a $1.50 for 5 or more gallons"<<endl <<endl;
cout<<"Enter 1 to include the car wash of 2 to cancel the car wash." << endl;
cin>>ans;

if (ans==Yes)

{
cout << "Please enter 1 for Ultra wash = $ 9.00, 2 Super wash = $7.00 ,3 for Regular wash= $ 5.00.";
cin >> car_wash_type;
}
switch(gas_type)
{

case '1':
price_of_gas = number_of_gallons * REGULAR_RATE;
cout << "The type of gas you selected is REGULAR." << endl;
cout << "The cost of your gas is $"<<price_of_gas << endl;
return 0;

case 2:
price_of_gas = number_of_gallons * MID_RATE;
cout << "The type of gas you selected is MID GRADE." << endl;
cout << "The cost of your gas is $"<<price_of_gas << endl;


case 3:
price_of_gas = number_of_gallons * PREMIUM_RATE;
cout << "The type of gas you selected is PREMIUM." << endl;
cout << "The cost of your gas is $"<<price_of_gas << endl;


case 4:
price_of_gas = number_of_gallons * DIESEL_RATE;
cout << "The type of gas you selected is DIESEL." << endl;
cout << "The cost of your gas is $"<<price_of_gas << endl;

default: cout<< " Thank You For Shopping by at MSU's Gas and GO!" <<endl;
}


switch( car_wash_type)
{

case 1:
wash_cost = ULTRA_WASH - _DISCOUNT;
cout << "The type of car wash you selected is ULTRA WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost << endl;


case 2:
wash_cost = SUPER_WASH - _DISCOUNT;
cout<< "The type of car wash you selected is SUPER WASH." << endl;
cout<< "The cost of your car wash is $"<< wash_cost<< endl;


case 3:
wash_cost = REGULAR_WASH - _DISCOUNT;
cout<<"The type of gas you selected is REGULAR WASH."<<endl;
cout<<"The cost of your car wash is $"<< wash_cost<<endl;

default: cout<<"Thank You For Shopping by at MSU's Gas and GO!"<<endl;
}

else (number_of_gallons==5,6,7,8,9);
{
cout<<"We also give a $1.50 discount with any purchase of 5 or more gallons."<<endl <<endl;
cout<<"Enter 1 to include the car wash of 2 to cancel the car wash." << endl;
cin>>ans;

case 1:
wash_cost = ULTRA_WASH - DISCOUNT_;
cout << "The type of car wash you selected is ULTRA WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost << endl;


case 2:
wash_cost = SUPER_WASH - DISCOUNT_;
cout << "The type of car wash you selected is SUPER WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost<< endl;


case 3:
wash_cost = REGULAR_WASH - DISCOUNT_;
cout << "The type of gas you selected is REGULAR WASH."<<endl;
cout << "The cost of your car wash is $"<< wash_cost<<endl;


case 0: cout<< " Thank You For Shopping by at MSU's Gas and GO!" <<endl;
}

}

system("pause");

return 0;
}
still having illegal case issues with the cases after "else(number_of_gallons==5,6,7,8,9);
Look at the ; you quoted. It doesn't belong there.

Also, there is no switch associated with the cases inside the code block where they're situated.


And you're going to need a break with your cases.

I didn't make any edits in this post, but I commented some changes you should check out.

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
further modified

#include < iostream>

# include <iomanip>

using namespace std;


double REGULAR_RATE = 3.899;
double MID_RATE = 3.999;
double PREMIUM_RATE = 4.199;
double DIESEL_RATE = 4.199;
double ULTRA_WASH = 9.000;
double SUPER_WASH = 7.000;
double REGULAR_WASH = 5.000;
double _DISCOUNT = 3.000;
double DISCOUNT_ = 1.500;
const char Yes = 1;
const char No = 2;
int main()

{
// variable declarations
double price_of_gas, number_of_gallons, wash_cost = 0;
int gas_type, car_wash_type, ans = 0;

// user input

cout<<"Welcome to MSU's Gas 'N' Go!"<<endl<<endl;
cout<<"This program allows users to calculate the price by entering the Type of gas and the number of Gallons.";
cout<<"It also offers the users a discounted car wash with the purchase of 5 or more gallons.";
cout<<"What type of gas would you like to purchase today?"<< endl;
cout << "Please enter 1 for Regular, 2 for Mid Grade, 3 for Premium, or 4 for Diesel."<<endl<<endl;
cin>>gas_type;
cout<<"Now, enter the number of gallons" << endl;
cin>>number_of_gallons;

if(number_of_gallons >=10)
{
cout<<"We also give a $3.00 discount with any purchase of 10 or more gallons, and a $1.50 for 5 or more gallons"<<endl <<endl;
cout<<"Enter 1 to include the car wash of 2 to cancel the car wash." << endl;
cin>>ans;

if (ans==Yes)

{
cout << "Please enter 1 for Ultra wash = $ 9.00, 2 Super wash = $7.00 ,3 for Regular wash= $ 5.00.";
cin >> car_wash_type;
}
switch(gas_type)
{ 

case '1':	//this is a character.  The value of this character is not 1
price_of_gas = number_of_gallons * REGULAR_RATE;
cout << "The type of gas you selected is REGULAR." << endl;
cout << "The cost of your gas is $"<<price_of_gas << endl;
return 0;

case 2:
price_of_gas = number_of_gallons * MID_RATE;
cout << "The type of gas you selected is MID GRADE." << endl;
cout << "The cost of your gas is $"<<price_of_gas << endl;


case 3:
price_of_gas = number_of_gallons * PREMIUM_RATE;
cout << "The type of gas you selected is PREMIUM." << endl;
cout << "The cost of your gas is $"<<price_of_gas << endl;


case 4:
price_of_gas = number_of_gallons * DIESEL_RATE;
cout << "The type of gas you selected is DIESEL." << endl;
cout << "The cost of your gas is $"<<price_of_gas << endl;

default: cout<< " Thank You For Shopping by at MSU's Gas and GO!" <<endl;
}


switch( car_wash_type)
{ 

case 1:
wash_cost = ULTRA_WASH - _DISCOUNT;
cout << "The type of car wash you selected is ULTRA WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost << endl;


case 2:
wash_cost = SUPER_WASH - _DISCOUNT;
cout<< "The type of car wash you selected is SUPER WASH." << endl;
cout<< "The cost of your car wash is $"<< wash_cost<< endl;


case 3:
wash_cost = REGULAR_WASH - _DISCOUNT;
cout<<"The type of gas you selected is REGULAR WASH."<<endl;
cout<<"The cost of your car wash is $"<< wash_cost<<endl;

default: cout<<"Thank You For Shopping by at MSU's Gas and GO!"<<endl;
}

//else is always true when all else if's and the if that precede it are false
else (number_of_gallons==5,6,7,8,9);  //semicolon?
{
cout<<"We also give a $1.50 discount with any purchase of 5 or more gallons."<<endl <<endl;
cout<<"Enter 1 to include the car wash of 2 to cancel the car wash." << endl;
cin>>ans;

//Where's the switch???
case 1:
wash_cost = ULTRA_WASH - DISCOUNT_;
cout << "The type of car wash you selected is ULTRA WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost << endl;


case 2:
wash_cost = SUPER_WASH - DISCOUNT_;
cout << "The type of car wash you selected is SUPER WASH." << endl;
cout << "The cost of your car wash is $"<< wash_cost<< endl;


case 3:
wash_cost = REGULAR_WASH - DISCOUNT_;
cout << "The type of gas you selected is REGULAR WASH."<<endl;
cout << "The cost of your car wash is $"<< wash_cost<<endl;


case 0: cout<< " Thank You For Shopping by at MSU's Gas and GO!" <<endl;
}

} 

system("pause");

return 0;
}
thanks so much!!
Topic archived. No new replies allowed.