将积分添加到分数

时间:2016-09-05 04:50:04

标签: c# math console

我正在建立一个控制台c#闪存卡游戏,我想保持一个分数将在多少正确的结尾显示。我正在考虑做这件事的最佳方法是什么我正在思考一个for循环,但它并没有为我工作,就像我认为它可能然后我仍然是编程的新手,所以我肯定也许我只是做错了什么。

所以,我有一个双重的答案。 因为我只需要一个单独使用另一个名为correctAnswer的int。 我以为我可以使用它来添加到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;

1 个答案:

答案 0 :(得分:1)

添加一小段代码后,这是您的代码。每当他正确回答时,答案会增加1.如果你想重置你的分数,你需要为那个时候发生的功能做一个功能,分数在连胜中减少三次。这是你的游戏。

           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;