【发布时间】:2013-10-13 15:23:11
【问题描述】:
我正在使用 c# 进行测试,但遇到了一个“小”问题。我在网上搜索了一个小时,但发现代码不起作用:(
我正在使用 c# 进行测试,并尝试在命令 promt 中做一个小测验
//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)。
我认为这与将字符串转换为布尔值有关。我试图删除“!”但这会产生相反的效果(只是说问题是错误的)。
希望有人能帮忙!
吉斯
【问题讨论】:
-
您已反转条件。如果用户键入“a”,那么答案是正确的,您应该删除!在平等的面前。请记住,大写的“A”与 Equals 的小写“a”不同。