In: Computer Science
Ice Cream Program Assignment
Write a program that uses a function to ask the user to choose an ice cream flavor from a menu (see output below.) You must validate the users input for the flavor of ice cream accounting for both upper and lower-case letters. You must give them an appropriate error message and allow them to try again. Once you have a valid flavor, your function will return the flavor back to the main() function.
Your main() function will then ask for the number of scoops. You must validate this data! Make sure that the user chooses at least 1 scoop but no more than 4. If they try another other, you must give them an error message and allow them to try again.
Your program will then calculate and display the cost of the ice cream. The cost of ice cream is $ .75 for the cone and $1.25 per scoop.
Your program will continue asking customers for the flavor and number of scoops until they choose ‘Q’ to quit.
The program will then send all of the data to a function to display the total number of cones sold, the total amount collected, and the total scoops of each type of ice cream sold.
Sample Output:
Please Choose your Favorite Flavor!
V - Vanilla
C - Chocolate
F - Fudge
Q - Quit
-----> v
How many scoops would you like? 2
Your ice cream cone cost $ 3.25 Please Choose your Favorite Flavor!
V - Vanilla
C - Chocolate
F - Fudge
Q - Quit
-----> c
How many scoops would you like? 5
That is an invalid number of scoops! You may only choose between 1 and 4
Please try again!
How many scoops would you like? 0
That is an invalid number of scoops! You may only choose between 1 and 4
Please try again!
How many scoops would you like? 3
Your ice cream cone cost $ 4.50 Please Choose your Favorite Flavor!
V - Vanilla
C - Chocolate
F - Fudge
Q - Quit
-----> s
How many scoops would you like? 1
Your ice cream cone cost $ 2.00 Please Choose your Favorite Flavor!
V - Vanilla
C - Chocolate
F - Fudge
Q - Quit
-----> q
The total number of cones sold: 3
The total scoops of vanilla sold: 2
The total scoops of chocolate sold: 3
The total scoops of fudge sold: 1
The total amount collected: $ 9.75
#include<iostream>
using namespace std;
char icecream()
{
char x;
cout<<"Please choose ypour favorite flavor!"<<endl;
cout<<" V - Vanilla\nC - Chocolate\nF - Fudge\nQ - Quit"<<endl;
cin>>x;
return x;
}
int main()
{
float n, total;
int v_count=0, c_count=0, f_count=0, no_of_cones=0;
char x=icecream();
while(1)
{
if(x=='v' || x=='V' || x=='c' || x=='C' || x=='f' || x=='F')
{
if(x=='v' || x=='V')
{
cout<<"How many scoops do you like?";
cin>>n;
if(n>=5 || n<=0)
{
cout<<"That is an invalid number of scoops. Please choosew between 1 and 4";
}
else
{
cout<<"Your icecream cone costs$"<<n*1.25 + 0.75;
}
total=total+n*1.25 + 0.75;
v_count+=v_count*n;
}
else if(x=='f' || x=='F')
{
cout<<"How many scoops do you like?";
cin>>n;
if(n>=5 || n<=0)
{
cout<<"That is an invalid number of scoops. Please choosew between 1 and 4";
}
else
{
cout<<"Your icecream cone costs$"<<n*1.25 + 0.75;
}
f_count+=f_count*n;
total=total+n*1.25 + 0.75;
}
else if(x=='c' || x=='C')
{
cout<<"How many scoops do you like?";
cin>>n;
if(n>=5 || n<=0)
{
cout<<"That is an invalid number of scoops. Please choosew between 1 and 4";
}
else
{
cout<<"Your icecream cone costs$"<<n*1.25 + 0.75;
}
c_count+=c_count*n;
total=total+n*1.25 + 0.75;
}
no_of_cones++;
}
else if(x=='q' || x=='Q')
{
break;
}
else
{
cout<<"Invalid input. Please try again!";
}
x=icecream();
}
cout<<"The total number of cones sold:"<<no_of_cones<<endl;
cout<<"The total scoops of vanilla sold:"<<v_count<<endl;
cout<<"The total scoops of chocolate sold:"<<c_count<<endl;
cout<<"The total scoops of fudge sold:"<<f_count<<endl;
cout<<"The total amount collected:"<<total;
return 0;
}