我试图在这里做一个简单的小测验,但是无论用户输入什么,用户总是会被告知他们有正确的答案,即使它是错误的。
这是我的源代码:您在这里看到的第一个类是 Program.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TheQuiz
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Welcome to the Quiz! \nYou'll be asked 20 questions! If you get one question wrong, you'll be out.\nHowever if you answer all 20 questions correctly, you'll be the MASTER!");
Console.WriteLine("\nLet us begin! Are you ready?\n\n");
Console.WriteLine("(Remember, TYPE in the correct answer. Every answer has ONE word only!\nAnd ALWAYS use a capital letter at the beginning of the answer: 'Answer')\n\n(Press Enter to continue...)");
Console.ReadKey();
Console.Clear();
Console.WriteLine("In what country was Adolf Hitler born?");
Console.ReadLine();
if (Answers.AnswerOne.Equals("Austria"))
{
Console.WriteLine("Congratulations! {0} is the correct answer!", Answers.AnswerOne);
}
else if (!Answers.AnswerOne.Equals(Answers.AnswerOne))
{
Console.WriteLine("Sorry! You wrote the wrong answer!\nThe correct answer was {0]", Answers.AnswerOne);
}
Console.ReadKey();
}
}
}
这是我的另一堂课,Answers.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TheQuiz
{
public class Answers
{
public static string AnswerOne = "Austria";
public static string AnswerTwo = "";
public static string AnswerThree = "";
public static string AnswerFour = "";
public static string AnswerFive = "";
public static string AnswerSix = "";
public static string AnswerSeven = "";
public static string AnswerEight = "";
public static string AnswerNine = "";
public static string AnswerTen = "";
public static string AnswerEleven = "";
public static string AnswerTwelve = "";
public static string AnswerThirteen = "";
public static string AnswerFourteen = "";
public static string AnswerFifteen = "";
public static string AnswerSixteen = "";
public static string AnswerSeventeen = "";
public static string AnswerEighteen = "";
public static string AnswerNineteen = "";
public static string AnswerTwenty = "";
}
}
所以正确的答案是奥地利,但是如果用户输入了德国之类的其他东西,它仍然表明它是正确的答案。
提前致谢。