我一直在C#上測試一個測驗程序幾個星期。除了最後一個細節之外,我已經盡其所能地工作了。我希望能夠通過測驗一次,然後在第二次嘗試中使用任何不正確的答案。在兩次嘗試結束時,我都想向用戶顯示評分。任何想法我將如何能夠做到這一點?這裏有一點我的代碼,我正在與:如何在我的測驗中存儲錯誤的答案並在第二次嘗試中重新填充它們
using System;
namespace Quiz
{
class MultipleChoiceQuiz
{
public static void CurrentQuestion(string correctAnswer)
{
do
{
string userAnswer = Console.ReadLine();
if (userAnswer != "A" && userAnswer != "B" && userAnswer != "C" && userAnswer != "D")
{
Console.WriteLine("\nError - Not a Valid Input - Please Enter Valid Input");
}
else
{
if (userAnswer == correctAnswer)
{
Console.WriteLine("\nThat is correct!");
break;
}
else if (userAnswer != correctAnswer)
{
Console.WriteLine("\nSorry, that is incorrect.");
break;
}
}
}
while (true);
}
public static void Questions()
{
Console.WriteLine("Chad Mitchell - ENGR 115 - USAF HC130J Power On Quiz\n");
Console.WriteLine("Please enter your first name: ");
string firstName = Console.ReadLine();
Console.WriteLine("\nWelcome to the HC-130J Power-On Quiz " + firstName + ".\n");
Console.WriteLine("Using the keyboard, please submit answers by using the \'ENTER\' key.\n");
Console.WriteLine("Please submit answers in CAPITAL letter form only.\n");
Console.WriteLine("Ready to begin " + firstName + "? Hit the \'ENTER\' key now...");
Console.ReadLine();
Console.Clear();
//Question 1
Console.WriteLine("Chad Mitchell - ENGR 115 - USAF HC130J Power On Quiz\n");
Console.WriteLine("Question 1 - What position does the ramp contol knob need to be in? " +
"\n\nA. 3N \nB. 1 \nC. 6N \nD. A or C \n\nWhat is your answer " + firstName + "?");
CurrentQuestion("D");
Console.Write("\nPress \'ENTER\' to continue...");
Console.ReadLine();
Console.Clear();
//Question 2
Console.WriteLine("Chad Mitchell - ENGR 115 - USAF HC130J Power On Quiz\n");
Console.WriteLine("Question 2 - After power is applied to the aircraft, the battery needs to be turned off? " +
"\n\nA. True \nB. False \n\nWhat is your answer " + firstName + "?");
CurrentQuestion("A");
Console.Write("\n");
Console.Write("\nPress \'ENTER\' to continue...");
Console.ReadLine();
Console.Clear();
//Question 3
Console.WriteLine("Chad Mitchell - ENGR 115 - USAF HC130J Power On Quiz\n");
Console.WriteLine("Question 3 - Above what temperature does air condition need to be applied to the aircraft while power is applied? " +
"\n\nA. 75 degrees Fahrenheit \nB. 100 degrees Fahrenheit \nC. 95 degrees Fahrenheit \nD. 85 degrees Fahrenheit \n\nWhat is your answer "
+ firstName + "?");
CurrentQuestion("C");
Console.Write("\n");
Console.Write("\nPress \'ENTER\' to continue...");
Console.ReadLine();
Console.Clear();
我有一個類和兩個方法。一種方法是將測驗中的答案評估爲對或錯。另一種是向用戶顯示所有問題和答案。任何人可能能夠給我的幫助將不勝感激。
存儲的答案 – UnholySheep