{
// 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;
}
{
// 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;
}
{
// 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;
}
further modified
#include < iostream>
# include <iomanip>
usingnamespace 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;
constchar Yes = 1;
constchar 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;
}