![]() |
| | #1 |
| Registered User Join Date: Nov 2009 Location: Can
Posts: 1
| C# McDonalds Program Help! 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);
}
}
}
|
| initialfresh is offline | |
| | #2 |
| Jack of many languages Join Date: Nov 2007 Location: Katy, Texas
Posts: 1,929
| 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. Memorable Quotes From Recent Posts: I can't remember. |
| Dino is offline | |
| | #3 |
| Super Moderator Join Date: Aug 2001
Posts: 7,470
| 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());
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.
__________________ If you aim at everything you will hit something but you won't know what it is. Last edited by Bubba; 11-03-2009 at 04:46 PM. |
| Bubba is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Issue with program that's calling a function and has a loop | tigerfansince84 | C++ Programming | 9 | 11-12-2008 01:38 PM |
| Need help with a program, theres something in it for you | engstudent363 | C Programming | 1 | 02-29-2008 01:41 PM |
| This is a simple program.. Help me please I think it has an error.. | lesrhac03 | C Programming | 4 | 02-21-2008 10:39 AM |
| My program, anyhelp | @licomb | C Programming | 14 | 08-14-2001 10:04 PM |