i am new to programming and am trying to do a weird assignment. Here are my instructions:
There is a drive-thru Car Wash that offers different services.
1) Regular Car Wash
2) Super Car Wash
3) Super Dooper Car Wash
4) Quit
The fee for each one of these services is different.
Prompt the user for type of service?
Ask the driver for his or her age?
If the user selects Regular Car Wash
Prompt the user for the number passengers in the car?
If there are more than 3 passengers
The price for the carwash is the number of passengers multiplied by the user’s age
display the price
display the grand total
Otherwise
display as many stars as the number of passengers
If the user select Super Car Wash
If the person is a senior citizen( 65 or older)
price is .50 cents multiplied by all the years in excess of 65
(Example : 67 years of age would be equal to $1.00)
otherwise
if the person’s age is even (e.g 44, 32)
display “No Charge”
otherwise
the price is equal to the person’s age
display the price
display the grand total
If the user selects Super Dooper Car Wash
Prompt for the number of passengers who are in the car(Must be less than 4:)?
If the user enters an invalid number prompt the user again.
For each passenger ask their age and their gender
if the passenger is a female
The price is the age of the passenger multiplied by $1.50
otherwise
The price is the age of the driver multiplied by $2.00
Display total for all the passengers in the car
Display Grand Total
At the end, when the user selects quit display the following pattern one character at a time (You would be displaying combinations of spaces and asterisks to come up with pattern, using two loops
*
**
***
****
Give a grand total for everyone
Here is my code:
#include <cstdio> //Header Files
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int choice, passengers, age, passage, a, x, y, row, space, asterisk;;
bool notValid;
char passgend, f, m;
double fee=0, grandtotal=0;
cout << "Welcome to the Fair Price Car Wash\n\n";
cout << "1) Regular Car Wash\n";
cout << "2) Super Car Wash\n";
cout << "3) SuperDooper Car Wash\n";
cout << "4) Quit\n\n\n";
cout << "Select one of the options:";
cin >> choice;
do //Validation for age
{
notValid=false;
printf ("\nHow old are you?");
cin >> age;
if (age<1 || age>115)
{
cout << "Invalid entry.";
notValid=true;
}
} while (notValid);
do //Validation for passengers
{
notValid=false;
cout << "\nHow many passengers do you have?";
cin >> passengers;
if (passengers <1 || passengers >10)
{
cout << "Invalid entry.";
notValid=true;
}
} while (notValid);
switch (choice)
{
case 1:
if (passengers>3)
{
fee=passengers*age;
grandtotal=grandtotal+fee;
printf ("%30s","The price for you is $");
printf ("%-5.2lf", fee);
cout << "\n\n";
printf ("%30s","The grand total is $");
printf ("%-5.2lf", grandtotal);
}
else
{
for(a=0;a<passengers;a++) //Display as many starts as the number of passengers
cout << "*\n";
grandtotal=grandtotal+fee;
printf ("%30s","The price for you is $");
printf ("%-5.2lf", fee);
cout << "\n\n";
printf ("%30s","The grand total is $");
printf ("%-5.2lf", grandtotal);
}
break;
case 2:
grandtotal=grandtotal+fee;
if (age>=65)
{
fee=(age-65)*.5;
printf ("%30s","The price for you is $");
printf ("%-5.2lf", fee);
cout << "\n\n";
}
else if(age% 2 == 0)
cout << "\nNo Charge\n";
else
{
fee=age;
grandtotal=grandtotal+fee;
printf ("%30s","The price for you is $");
printf ("%-5.2lf", fee);
printf ("%30s","The grand total is $");
printf ("%-5.2lf", grandtotal);
cout << "\n\n";
}
break;
case 3:
do{
notValid=false;
cout << "\nHow many passengers do you have?";
cin >> passengers;
if (passengers >=4)
{
cout << "Invalid entry.";
notValid=true;
}
}while (notValid);
do{
a=0;
a++;
cout << "\nEnter gender of passenger number ";
cout << a, ":";
cin >> passgend;
cout << "\nEnter age of passenger number ";
cout << a, ":";
cin >> passage;
if (passgend==f)
{
fee=passage*1.5;
grandtotal=grandtotal+fee;
printf ("%30s","The price for you is $");
printf ("%-5.2lf", fee);
printf ("%30s","The grand total is $");
printf ("%-5.2lf", grandtotal);
cout << "\n\n";
}
else
{
fee=2*age;
grandtotal=grandtotal+fee;
printf ("%30s","The price for you is $");
printf ("%-5.2lf", fee);
printf ("%30s","The grand total is $");
printf ("%-5.2lf", grandtotal);
cout << "\n\n";
}
}while(a<passengers);
break;
case 4:
for(row=1; row<5; row++)
{
for(space=0; space<4-row; space++)
printf (" ");
for(asterisk=1; asterisk<=row; asterisk++)
printf("*");
cout << endl ;
}
printf ("%30s","The grand total is $");
printf ("%-5.2lf", grandtotal);
cout << "\n\n";
default:
cout << "Invalid entry\n\n";
system("pause");
}
}
Why does my program stop after the validation? And why does it still display input prompts when I select #4?