2015-10-27 41 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來擺脫編譯器的警告,但是我會添加一個驗證,用戶輸入一個有效的選項。

相關問題