Question

Ice Cream Program Assignment Write a program in c# that uses a function to ask the...

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

Homework Answers

Answer #1

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");
      
   }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
At Izzy’s Ice Cream you can buy an ice cream cone a lot of different ways....
At Izzy’s Ice Cream you can buy an ice cream cone a lot of different ways. You have 3 choices for the type of cone you can get: sugar cone, waffle cone or chocolate coated cone. You have 6 choices for ice cream flavor: chocolate, vanilla, strawberry, cherry, peach or banana. You have 5 choices for toppings: jimmies, butterscotch syrup, peanuts, gummy bears or “M and Ms”. You can order one of three sizes: small, medium or large. When you...
Coffee Order Structure Assignment Write a program that uses a structure for a coffee order. A...
Coffee Order Structure Assignment Write a program that uses a structure for a coffee order. A coffee order consists of a double price, a string for flavor, and characters for cream (Y/N), sugar (Y/N), and coffee size (S/M/L). Your main() function will call an order function that will ask the user for the flavor, size and whether or not they want cream or sugar. Your main() function will then create a coffee order structure and assign all of the values...
Main Street Ice Cream Company uses a plantwide allocation method to allocate overhead based on direct...
Main Street Ice Cream Company uses a plantwide allocation method to allocate overhead based on direct labor-hours at a rate of $3 per labor-hour. Strawberry and vanilla flavors are produced in Department SV. Chocolate is produced in Department C. Sven manages Department SV and Charlene manages Department C. The product costs (per thousand gallons) follow. Strawberry Vanilla Chocolate Direct labor (per 1,000 gallons) 752 827 1127 Raw materials (per 1,000 gallons) 802 502 602 Required: a. If the number of...
2. Yan has preferences over chocolate(x)and vanilla(y)ice cream that are represented by the following utility function:...
2. Yan has preferences over chocolate(x)and vanilla(y)ice cream that are represented by the following utility function: u(x,y) = xy4 3 Notice the power (4/3) just affects good y. (a) Yan is an ice cream connoisseur, meaning, when deciding how much ice cream to buy, there is a minimum level of utility he must reach with ice cream consumption. But he doesn’t want to spend too much money because he is a graduate student. Setup Yan’s constrained expenditure minimization problem. (1...
Question 2: Greg owns a local ice cream store. His business started small, but over the...
Question 2: Greg owns a local ice cream store. His business started small, but over the years, word of mouth brought more people into town to try his delicious homemade ice cream. Since business is booming, Greg has decided to expand his business and open three additional stores in surrounding towns. A. What is an organizational structure? How does it develop? In your opinion, what does growth like this require, in terms of structure? B. Differentiate between work groups and...
In this assignment you will write a program that compares the relative strengths of two earthquakes,...
In this assignment you will write a program that compares the relative strengths of two earthquakes, given their magnitudes using the moment magnitude scale. Earthquakes The amount of energy released during an earthquake -- corresponding to the amount of shaking -- is measured using the "moment magnitude scale". We can compare the relative strength of two earthquakes given the magnitudes m1 and m2 using this formula: f=10^1.5(m1−m2) If m1>m2, the resulting value f tells us how many times stronger m1...
C++ Fahrenheit to Celsius Tables Write a program that first asks the user which Temperature scale...
C++ Fahrenheit to Celsius Tables Write a program that first asks the user which Temperature scale conversion he/she would like to perform: 1. Convert F to C 2. Convert C to F 3. Quit What is your choice? Then it asks the user for input for three real number variables: start_temp, end_temp, temp_incr. It will then produce a two column Fahrenheit to Celsius table or a two column Celsius to Fahrenheit table, depending on the choice. For choice 1, the...
C++ PROGRAM SPECIFICATION For the assignment, we will use the previous assignment’s program that determines whether...
C++ PROGRAM SPECIFICATION For the assignment, we will use the previous assignment’s program that determines whether a college class room is in violation of fire law regulations regarding the maximum room capacity and add more logic to that program. We will need to make the following enhancements… The program should now determine the number of classes, and should do so by generating a unique, random number. Replace taking user input for the number of rooms with a computer generated number...
Write the following function and provide a program to test it (main and function in one...
Write the following function and provide a program to test it (main and function in one .py) 5 pts def readFloat(prompt) that displays the prompt string, followed by a space, reads a floating-point number in, and returns it. Below is how you’re going to call the function: salary = readFloat(“Please enter your salary:”) percentageRaise = readFloat(“What percentage raise would you like?”) print("The salary is", salary) print("The raise percentage is", percentageRaise) keep it simple, python
Write a program in C++ coding that asks the user to input an integer between 25...
Write a program in C++ coding that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT