2015-10-27 17 views
-4
Console.WriteLine("enter the sirial number of the followin bevrege you want to buy"); 
Console.WriteLine("beverge      cost"); 
Console.WriteLine("1.ness cafe     2.25"); 
Console.WriteLine("2.black coffe    2.25"); 
Console.WriteLine("3.tea      1.30"); 
Console.WriteLine("4.hot choclate    2.50"); 
Console.WriteLine("5.soup      3.10"); 
Console.WriteLine("6.coca cola     3.30"); 
Console.WriteLine("7.orange juice    3.20"); 
int sirial; 
sirial = int.Parse(Console.ReadLine()); 
double mouny, cost; 
Console.WriteLine("enter how much ouny you enterd to the machine "); 
mouny = double.Parse(Console.ReadLine()); 


    if (sirial == 1 || sirial == 2) 
     cost = 2.25; 
    if (sirial == 3) 
     cost = 1.30; 
    if (sirial == 4) 
     cost = 2.50; 
    if (sirial == 5) 
     cost = 3.10; 
    if (sirial == 6) 
     cost = 3.30; 
    if (sirial == 7) 
     cost = 3.20; 


if (mouny == cost) 
    Console.WriteLine(" n/ thank you for buying"); 
+2

如果你输入8会发生什么?编译器对此并不满意。 – Steve

+0

我现在他们告诉我们像编译器只写入类型数字从1到8 –

+0

有什么问题? –

回答

3

如果用户输入的号码不是1到7,那么cost将不会被分配一个值。你可以给它一个初始值0来摆脱编译器的警告,但是我会添加一个验证,用户输入一个有效的选项。

相关问题