2013-10-20 92 views
0

這是我迄今爲止。我的問題是,當你輸入正確或不正確的答案時,沒有任何案件正在響應。我不確定該從哪裏出發。該程序會要求您回答兩個隨機數字相乘。然後它會給你八個答覆中的一個。c#切換問題。家庭作業

 int result = 0; 
     int caseSwitch = 0; 

     string question = DoMultiplication(out result); 
     Console.WriteLine(question); 
     int answer = Convert.ToInt32(Console.ReadLine()); 

     if (answer == result) 
     { 
      switch (caseSwitch) 
      { 
       case 1: 
        Console.WriteLine("Very Good"); 
        break; 

       case 2: 
        Console.WriteLine("Excellent"); 
        break; 

       case 3: 
        Console.WriteLine("Nice Work"); 
        break; 

       case 4: 
        Console.WriteLine("Keep up the good work!"); 
        break; 

      } 

     } 
     else 
     { 
      switch (caseSwitch) 
      { 


       case 1: 
        Console.WriteLine("No, Please Try Again."); 
        break; 

       case 2: 
        Console.WriteLine("Wrong, Try Once More"); 
        break; 

       case 3: 
        Console.WriteLine("Don't Give Up!"); 
        break; 

       case 4: 
        Console.WriteLine("No, Keep Trying!"); 
        break; 
+1

caseSwitch始終爲0 – jfin3204

+0

caseSwitch始終爲0,所以交換機永遠落空不寫任何東西來安慰 – geedubb

+0

我會在哪裏看看看如何從4個案例中挑選出來?我發現將caseSwitch分配給1總是會給我回應。 –

回答

1

CaseSwitch總是= 0 您需要將值分配給它,和或默認情況下添加到您的開關。

0

你有你的int caseSwitch = 0;,我沒有看到你在你的代碼中將它改爲1-4中的任何一個。那麼,如果你沒有caseSwitch改變,你期望它做什麼...

2

caseSwitch總是0,所以你的交換機將永遠不會寫任何東西到控制檯。

如果你想有一個隨機響應,你可以做這樣的事情:

int result = 0; 
    int caseSwitch = new Random().Next(1, 4); 

    string question = DoMultiplication(out result); 
    Console.WriteLine(question); 
    int answer = Convert.ToInt32(Console.ReadLine()); 

    if (answer == result) 
    { 
     switch (caseSwitch) 
     { 
      case 1: 
       Console.WriteLine("Very Good"); 
       break; 

      case 2: 
       Console.WriteLine("Excellent"); 
       break; 

      case 3: 
       Console.WriteLine("Nice Work"); 
       break; 

      case 4: 
       Console.WriteLine("Keep up the good work!"); 
       break; 

     } 

    } 
    else 
    { 
     switch (caseSwitch) 
     { 


      case 1: 
       Console.WriteLine("No, Please Try Again."); 
       break; 

      case 2: 
       Console.WriteLine("Wrong, Try Once More"); 
       break; 

      case 3: 
       Console.WriteLine("Don't Give Up!"); 
       break; 

      case 4: 
       Console.WriteLine("No, Keep Trying!"); 
       break; 
+0

,請看下面的答案 - 這是正確的答案。 –

+0

嘿謝謝一堆。 –

+0

請標記爲答案,如果它幫助你 – geedubb