2016-09-05 10 views
0

私はコンソールC#フラッシュカードゲームを構築していますが、私はスコアが正しい場所の最後に表示されるようにしておきたいと思います。私はこれを行うための行動の最善の策を考えています。私はforループを考えていましたが、それは私が考えていたように私にとってはうまくいきませんでした。ちょうど何か間違っている。スコアにポイントを追加する

私は答えをdoubleと呼んでいます。 私はcorrectAnswerと呼ばれる別のintを使用しているので、私は1つしか必要ありません。 私はそれをforループに追加するのに使うことができると思っていましたが、それは計画どおりに行かなかった そう、私はスコアにポイントを追加するための最善の行動コースかもしれないものを求めています。私はまた、別の問題を私は答えを使用することによってそれが間違って取得してもポイントを追加するが表示されますが、私は一度これをソートして解決することができます。

    double answer = 0; 
        int correctAnswer = Convert.ToInt32(answer); 

        for (correctAnswer = 0; correctAnswer <= answer; correctAnswer++) ; 

        ///Setting up the switch statement 
        ///switch (variable) 
        ///  case 1: 
        ///  code; 
        ///  break; 
        ///  
        switch (opSign) 
        { 
         case 1: 
          Console.WriteLine("What is the answer to " + num1 + (" Times " + num2 + " ?")); 
          answer = Convert.ToInt32(Console.ReadLine()); 
          if (answer == num1 * num2) 
          { 

           speechAnswers(); 
           Console.WriteLine("You entered " + answer + " as the answer to " + num1 + " times " + num2 + "." + " You are correct good job! "); 
          } 
          else if (answer != num1 * num2) 
           Console.WriteLine("You are incorrect please try again"); 
          break; 
+0

あなた 'correctAnswer'変数の使用は何かを追加し、答えが正しいとき、コードが起こる書くたびに?なぜそれは答えと同じであると宣言しますか? – Mark

答えて

1

小さなコードを追加した後のコードです。彼が正しく答えるたびに、Answerが1ずつ増えます。あなたのスコアをリセットしたい場合は、スコアが3回連続して減少したときにそれを実行する必要があります。これはあなたのゲームです。

  double answer = 0; 
      int correctAnswer = Convert.ToInt32(answer); 

        for (correctAnswer = 0; correctAnswer <= answer; correctAnswer++) ; 

        ///Setting up the switch statement 
        ///switch (variable) 
        ///  case 1: 
        ///  code; 
        ///  break; 
        ///  
        switch (opSign) 
        { 
         case 1: 
          Console.WriteLine("What is the answer to " + num1 + (" Times " + num2 + " ?")); 
          answer = Convert.ToInt32(Console.ReadLine()); 
          if (answer == num1 * num2) 
          { 

           speechAnswers(); 
           Console.WriteLine("You entered " + answer + " as the answer to " + num1 + " times " + num2 + "." + " You are correct good job! "); 
           score += 1; // every time the answer is correct, score is incremented by 1. 
          } 
          else if (answer != num1 * num2) 
           Console.WriteLine("You are incorrect please try again"); 
         // what happens on loss 
          break; 

あなたはこの score += 1;

関連する問題