我正在使用 c# 进行测试并遇到了一个“小”问题。我在网上搜索了一个小时,但发现代码不起作用:(
我正在使用 c# 进行测试并尝试在命令提示符中进行小测验
//variables questions, Vraag is question, Solution is the solution, and Keuze is the three choices (a,b and c)
string Vraag1 = ("Wat is de hoofstad van Oostenrijk?");
string Solution1 = ("Wenen");
string Keuze1 = ("a: Wenen b: Rome c: Kiev");
string Vraag2 = ("Hoe heet de hoogste berg van Afrika?");
string Solution2 = ("De Kilimanjaro");
string Keuze2 = ("a: De Mount-everest b: De Kilimanjaro c: De Aconcagua");
string Vraag3 = ("Wie was de uitvinder van de gloeilamp?");
string Solution3 = ("Edison");
string Keuze3 = ("a: Thomas Edison b: Albert Einstein c: Abraham Lincoln");
//Other variables
//entered1, 2 and 3 are variables that the user typed in
//code
//Question 1
Console.WriteLine("Vraag 1:");
Console.WriteLine();
Console.WriteLine(Vraag1);
Console.WriteLine();
Console.Read();
Console.WriteLine(Keuze1);
Console.Read();
string entered1 = Console.ReadLine();
Boolean enteredbool1 = !entered1.Equals("a");
if (enteredbool1)
{
Console.ForegroundColor = (ConsoleColor.Green);
Console.WriteLine("Goedzo, op naar de volgende!");
}
else
{
Console.WriteLine("FOUT!");
}
我的问题是,如果用户回答“a”,它说它很好(goedzo),但如果他输入 b,它给出的结果相同(fout)。
我认为这与将字符串转换为布尔值有关。我试图删除“!” 但这会产生相反的效果(只说问题是错误的)。
我希望有人能帮帮忙!
吉斯