Ice Cream Program Assignment
Write a program in c# 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
Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate
the question. Thank You So Much.
using System.IO;
using System;
class Program
{
static void printMenu() {
Console.WriteLine("Please Choose
your Favorite Flavor!");
Console.WriteLine("\t V -
Vanilla");
Console.WriteLine("\t C -
Chocolate");
Console.WriteLine("\t F -
Fudge");
Console.WriteLine("\t Q -
Quit");
}
static char getInput() {
while(true) {
Console.WriteLine("\t Enter your choice : ");
String input =
Console.ReadLine();
input =
input.ToLower();
char choice =
input[0];
if(choice=='v'
|| choice=='c' ||choice=='f' ||choice=='q') {
return choice;
}else {
Console.WriteLine("That is an invalid number of
scoops! You may only choose between 1 and 4");
}
}
}
static void Main()
{
double totalCollection=0;
int coneCount=0;
int vanillaCount=0;
int chocolateCount=0;
int fudgeCount=0;
while(true) {
printMenu();
double
amount=0;
char choice =
getInput();
if(choice=='q')
{
break;
}else
if(choice=='v') {
vanillaCount++;
}else
if(choice=='c') {
chocolateCount++;
}else
if(choice=='f') {
fudgeCount++;
}
int x;
coneCount++;
amount
+=.75;
while(true)
{
Console.WriteLine("\tHow many scoops would you
like?");
x = Convert.ToInt32(Console.ReadLine());
if(x>=1 && x<=4) {
break;
}else {
Console.WriteLine("\tThat is
an invalid number of scoops! \nYou may only choose between 1 and
4\nPlease try again!");
}
}
amount +=
x*1.25;
totalCollection
+= amount;
}
Console.WriteLine("The total number
of cones sold: "+coneCount+"\n");
Console.WriteLine("The total scoops
of vanilla sold: "+vanillaCount+"\n");
Console.WriteLine("The total scoops
of chocolate sold:"+chocolateCount+"\n");
Console.WriteLine("The total scoops
of fudge sold: "+fudgeCount+"\n");
Console.WriteLine("The total amount
collected:"+totalCollection+"\n");
}
}
Get Answers For Free
Most questions answered within 1 hours.