C# McDonalds Program Help!

This is a discussion on C# McDonalds Program Help! within the C# Programming forums, part of the General Programming Boards category; I can't figure out how to assign the value of the item to a variable and store it to be ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Location
    Can
    Posts
    1

    C# McDonalds Program Help!

    I can't figure out how to assign the value of the item to a variable and store it to be used later, So i can add it to the other items to give the total of the order.

    Please Help!
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ex6_2
    {
        class Program
        {
            static void Main(string[] args)
            {
                string userin;
                char sandwichch;
                char friesch;
                char drinkch;
                int sandwich = 0, fries = 0, drink = 0;
                double total = 0.0;
    
                Console.WriteLine("(a) Big Mac - $3.99         (b) McChicken - $3.99");
                Console.WriteLine("(c) Filet-O-Fish - $3.00    (d) No Sandwich");
                Console.WriteLine("Please select sandwich: ");
                userin = Console.ReadLine();
                sandwichch = userin[0];
                switch (sandwichch)
                {
                    case 'a': //bigmac
                        sandwich = 3.49;
                        sandwich = Convert.ToInt32(Console.ReadLine());
                        break;
                    case 'b': //mcchicken
                        sandwich = 3.49;
                        sandwich = Convert.ToInt32(Console.ReadLine());
                        break;
                    case 'c': //filetofish
                        sandwich = 3.00;
                        sandwich = Convert.ToInt32(Console.ReadLine());
                        break;
                    case 'd': //nosandwich
                        sandwich = 0.00;
                        sandwich = Convert.ToInt32(Console.ReadLine());
                        break;
                    default:
                        total = 0.0;
                        Console.WriteLine("Invalid Input");
                        break;
                }
                Console.WriteLine("(a) Large - $2.25 (b) Medium - $1.75 (c) Small - $1.75 (d) No Fries");
                Console.WriteLine("Please select fries size: ");
                userin = Console.ReadLine();
                fries = userin[0];
                switch (friesch)
                {
                    case 'a': //large
                        fries = 2.25;
                        fries = Convert.ToInt32(Console.ReadLine());
                        break;
                    case 'b': //medium
                        fries = 1.75;
                        fries = Convert.ToInt32(Console.ReadLine());
                        break;
                    case 'c': //small
                        fries = 1.25;
                        fries = Convert.ToInt32(Console.ReadLine());
                        break;
                    case 'd': //no
                        fries = 0.00;
                        fries = Convert.ToInt32(Console.ReadLine());
                        break;
                    default:
                        total = 0.0;
                        Console.WriteLine("Invalid Input");
                        break;
                }
                Console.WriteLine("(a) Large - $1.75 (b) Medium - $1.60 (c) Small - $1.30 (d) No Drink");
                Console.WriteLine("Please select drink size: ");
                userin = Console.ReadLine();
                drink = userin[0];
                switch (drinkch)
                {
                    case 'a': //large
                        drink = 1.75;
                        drink = Convert.ToInt32(Console.ReadLine());
                        break;
                    case 'b': //medium
                        drink = 1.60;
                        drink = Convert.ToInt32(Console.ReadLine());
                        break;
                    case 'c': //small
                        drink = 1.30;
                        drink = Convert.ToInt32(Console.ReadLine());
                        break;
                    case 'd': //no
                        drink = 0.00;
                        drink = Convert.ToInt32(Console.ReadLine());
                        break;
                    default:
                        total = 0.0;
                        Console.WriteLine("Invalid Input");
                        break;
                }
                if (sandwich >= 3.00 && fries >= 1.25 && drink >=1.30)
                {
                    total = sandwich + fries + drink - 0.75;
                }
                else
                {
    
                }
                Console.WriteLine("Your total is: {0:0.0}", total);
            }
        }
    }

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    I used to love to eat Filet O Fish sandwiches, until I read the fat content. Sigh.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    Code:
    case 'a': //bigmac
                        sandwich = 3.49;
                        sandwich = Convert.ToInt32(Console.ReadLine());
                        break;
                    case 'b': //mcchicken
                        sandwich = 3.49;
                        sandwich = Convert.ToInt32(Console.ReadLine());
                        break;
                    case 'c': //filetofish
                        sandwich = 3.00;
                        sandwich = Convert.ToInt32(Console.ReadLine());
                        break;
                    case 'd': //nosandwich
                        sandwich = 0.00;
                        sandwich = Convert.ToInt32(Console.ReadLine());
    You assign sandwich to a value and then proceed to blow it away in the next line. You need to setup a dictionary or a 2D array and assign the values in that way. What you are attempting to do, or at least what it looks like, is extract the value from what is printed on screen. While you can probably find a way to do that it is not ideal. Your output should be a way to display what is in memory to the user, not the other way around. Don't use video to compute what it is memory.

    Here is a sample of a dictionary that maps a string to a float or in .NET terms a System.String to a System.Single.
    key..........value
    "Big mac",3.49

    All you do from here is lookup sandwich in the dictionary and it will return 3.49 or the value associated with Big mac. In order to make a dynamic menu system you can use the same type of approach.
    Here is a dictionary that maps from a String to a String which might seem odd and it is but it does work. Since you are noticing that this is an odd construct it should clue you in that this is not the only way way to arrive at Big mac from the letter a and that that there might be a better approach.

    key..value
    "a","Big mac"

    Now when the user presses 'a' you get the value Big mac. Use the value Big mac to lookup it's price in your other dictionary. As long as your dictionary matches what is displayed on screen it will work.
    Last edited by VirtualAce; 11-03-2009 at 03:46 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21