Click here to Skip to main content
15,889,527 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C#
namespace Food
{
    class Program
    {
        static void Main(string[] args)
        {
            double menu1, menu2, menu3, menu4, menu5, total, money,change;

            money = 20;
            menu1 = 1.00;
            menu2 = 0.79;
            menu3 = 1.20;
            menu4 = 0.50;
            menu5 = 1.25;


            
            Console.Write("Please enter ammount of cheeseburgers purchased:");
             menu1 = double.Parse(Console.ReadLine());
             Console.Write("Please enter ammount of hamburgers purchased:");
             menu2 = double.Parse(Console.ReadLine());
             Console.Write("Please enter ammount of chicken sandwhiches purchased:");
             menu3 = double.Parse(Console.ReadLine());
             Console.Write("Please enter ammount of french fries purchased:");
             menu4 = double.Parse(Console.ReadLine());
             Console.Write("Please enter ammount of soda's purchased:");
             menu5 = double.Parse(Console.ReadLine());

             total = money - menu1 - menu2 - menu3 - menu4 - menu5;
             Console.Write("Your total is :" + total);
             Console.ReadLine();

             change = money - total;
             Console.Write("Your change is :" + change);
             

             
            
             

             Console.ReadLine();
              
        }
    }
}

The assignment is:
CSS
FOOD!!!!!!

Your parents have given you a total of $20 to go out and buy dinner for your family.  You go to a fast food place which has the following prices for food/drinks:
Cheeseburger: $1.00
Hamburger: $0.79
Chicken Sandwich: $1.20
French Fries: $0.50
Soda: $1.25

You must create a program that will calculate if you can afford all that you want to order.  The order of the task should be something like the following:
Ask the user for how many cheeseburgers.
Calculate the new total.
Ask the user for how many hamburgers.
Calculate the new total.
...
Do this for every item on the menu.
At the end of your program, you will need to output the total, with a dollar sign, and whether or not you have enough money for all of your food and drinks.  If you have enough money, also output how much change you will receive.  Please remember to use doubles for your variables, since you are working with decimals.
Posted
Comments
Philippe Mori 1-Nov-11 18:37pm    
Effectively,. the program is wrong... Try it on paper. For example, if you buy 2 hanmburgers and a french fries, it will cost you $2.08. If you have a $20, then the change will be $17.92.

Then when you understant how to compute costs and change, write the program so that it will do the proper calculation.
BillWoodruff 2-Nov-11 1:42am    
To me this is an impossible-to-calculate scenario: you don't specify how many family members there are, or any contraints or priorities : if there are five family members: is it okay if only three get cheesburgers, one gets a hamburger, and three get only fries and sodas ?

Well, for starters:

1. You have set the values of variables to the price of the menu items they represent:
C#
menu1 = 1.00;

Then you set the same variables to the quantity of items being ordered:
C#
menu1 = double.Parse(Console.ReadLine());

These variables no longer hold the price per item. You should have a separate set of variables to hold the number of menu items requested and then multiply the price per item times the number of items:
C#
int requested1, requested2, requested3, requested4, requested5;
requested1 = int.Parse(Console.ReadLine());


2. It appears that you are asking the user how much money they are going to spend on cheeseburgers, but this is not what the assignment asks you to do. You should ask how many cheeseburgers the user wants and calculate how much it will cost them.

3. When you calculate the total, you are actually calculating the change:
C#
total = money - menu1 - menu2 - menu3 - menu4 - menu5;

The total should actually be the sum of each menu item requested times the price of that menu item:
C#
total = (menu1 * requested1) + (menu2 * requested2) + (menu3 * requested3) + (menu4 * requested4) + (menu5 * requested5);

And the change:
C#
change = money - total;

If the change is negative, then you do not have enough money and should not be outputting change.

This should give you a few things to look at. Keep in mind, the assignment also asks you to calculate a running total as the different menu items are ordered.
 
Share this answer
 
v3
This is off topic. It has nothing to do with programming. We cannot help people who did not master elementary calculations. Back to elementary school!

—SA
 
Share this answer
 
Comments
JOAT-MON 1-Nov-11 19:02pm    
It has to do with basic understanding of programming. It also has to do with the math issue you pointed out, but there is a real programing problem here as well: fundamental understanding of the use of variables and following the spec.
Sergey Alexandrovich Kryukov 1-Nov-11 21:05pm    
Yes, yes, sure, but even the discussion of it boring...
--SA
BillWoodruff 2-Nov-11 1:43am    
I would hope we would show tolerance for very beginner questions.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900