我创建了一个多项选择的 C# 控制台程序,我放置了一个奖励阶段,但是当它到达它时,没有任何显示
I created a multiple choice c# console program and i placed a bonus stage but when it reaches it nothing shows up
我创建了一个多选 C# 控制台程序,我放置了一个奖励阶段,如果您获得完美的 5 分,该阶段就会触发,但当它达到它时,什么也没有显示。
为什么?
所有其他如果工作除了奖金有人可以告诉我如何解决这个问题吗?
对不起,如果我的编码很新手 (int,string,if)
{
int score = 0;
string ansr1 = "";
string ansr2 = "";
string ansr3 = "";
string ansr4 = "";
string ansr5 = "";
string bonus1 = "";
Console.WriteLine("Welcome to my quiz user!(please type your'e answers in lower case letters)\nWhat is your'e name?\n");
string name = Console.ReadLine();
Console.Clear();
Console.WriteLine("Okay "+name+" lets start!\n");
Console.Beep(500, 500);
Console.Beep(500, 500);
Console.Beep(500, 500);
Console.Beep(660, 2500);
Console.Clear();
//no.1
Console.WriteLine("Question 1\nWhat colour is the sky "+name+"?\na.blue\nb.green\nc.red\n");
ansr1 = Console.ReadLine();
Console.Clear();
if (ansr1 == "a")
{
score = score + 1;
Console.WriteLine("Correct!\n"+name+"'s score:"+score+"\n");
}
else
{
Console.WriteLine("Wrong!\n"+name+"'s score:"+score+"\n");
}
Console.Beep(600, 1500);
Console.Clear();
//no.2
Console.WriteLine("Question 2\nHow many stars are there on the american flag "+name+"?\na.21\nb.72\nc.50\n");
ansr2 = Console.ReadLine();
Console.Clear();
if (ansr2 == "c")
{
score = score+1;
Console.WriteLine("Correct\n"+name+"'s score:"+ score+"\n");
}
else
{
Console.WriteLine("Wrong\n"+name+"'s score:"+score+"\n");
}
Console.Beep(700, 1500);
Console.Clear();
//no.3
Console.WriteLine("Question 3\n"+name+",If you were in third place and you over take someone in second place what place would you be in now?\na.first\nb.second\nc.third\n");
ansr3 = Console.ReadLine();
Console.Clear();
if (ansr3 == "b")
{
score = score+1;
Console.WriteLine("Correct\n"+name+"'s score:" + score+"\n");
}
else
{
Console.WriteLine("Wrong\n"+name+"'s score:" + score+"\n");
}
Console.Beep(800, 1500);
Console.Clear();
//no.4
Console.WriteLine("Question 4\n" + name + ",what is the tallest mountain in the world?\na.Everest\nb.Fuji\nc.Bromo\n");
ansr4 = Console.ReadLine();
Console.Clear();
if (ansr4 == "a")
{
score = score + 1;
Console.WriteLine("Correct\n" + name + "'s score:" + score + "\n");
}
else
{
Console.WriteLine("Wrong\n" + name + "'s score:" + score + "\n");
}
Console.Beep(900, 1500);
Console.Clear();
//no.5
Console.WriteLine("Question 3\n" + name + ",If you were in third place and you over take someone in second place what place would you be in now?\na.first\nb.second\nc.third\n");
ansr5 = Console.ReadLine();
Console.Clear();
if ((ansr5 == "b") && (score == 5))
{
//bonus level
Console.WriteLine("Congratulations" + name + "you have scored a perfect 5!\nWould you like to enter the bonus stage?\nIf you lose this you lose the game\nbut if you pass you will receive 5 points.\nYes, or No?");
bonus1 = Console.ReadLine();
if (bonus1 == "yes")
{
}
else
{
Console.WriteLine();
}
}
else if (ansr5 == "b")
{
score = score + 1;
Console.WriteLine("Correct\n" + name + "'s score:" + score + "\n");
}
else
{
Console.WriteLine("Wrong\n" + name + "'s score:" + score + "\n");
}
Console.Beep(1000, 1500);
Console.Clear();
Console.ReadKey();
}
}
}
您在查看分数==5 的奖金时,您的最佳分数只能是 4。我想你忘了在第五个问题后增加分数。您必须在第 5 个问题后检查 score==4 或 increment score。这是更新的代码。
{
int score = 0;
string ansr1 = "";
string ansr2 = "";
string ansr3 = "";
string ansr4 = "";
string ansr5 = "";
string bonus1 = "";
Console.WriteLine("Welcome to my quiz user!(please type your'e answers in lower case letters)\nWhat is your'e name?\n");
string name = Console.ReadLine();
Console.Clear();
Console.WriteLine("Okay "+name+" lets start!\n");
Console.Beep(500, 500);
Console.Beep(500, 500);
Console.Beep(500, 500);
Console.Beep(660, 2500);
Console.Clear();
//no.1
Console.WriteLine("Question 1\nWhat colour is the sky "+name+"?\na.blue\nb.green\nc.red\n");
ansr1 = Console.ReadLine();
Console.Clear();
if (ansr1 == "a")
{
score = score + 1;
Console.WriteLine("Correct!\n"+name+"'s score:"+score+"\n");
}
else
{
Console.WriteLine("Wrong!\n"+name+"'s score:"+score+"\n");
}
Console.Beep(600, 1500);
Console.Clear();
//no.2
Console.WriteLine("Question 2\nHow many stars are there on the american flag "+name+"?\na.21\nb.72\nc.50\n");
ansr2 = Console.ReadLine();
Console.Clear();
if (ansr2 == "c")
{
score = score+1;
Console.WriteLine("Correct\n"+name+"'s score:"+ score+"\n");
}
else
{
Console.WriteLine("Wrong\n"+name+"'s score:"+score+"\n");
}
Console.Beep(700, 1500);
Console.Clear();
//no.3
Console.WriteLine("Question 3\n"+name+",If you were in third place and you over take someone in second place what place would you be in now?\na.first\nb.second\nc.third\n");
ansr3 = Console.ReadLine();
Console.Clear();
if (ansr3 == "b")
{
score = score+1;
Console.WriteLine("Correct\n"+name+"'s score:" + score+"\n");
}
else
{
Console.WriteLine("Wrong\n"+name+"'s score:" + score+"\n");
}
Console.Beep(800, 1500);
Console.Clear();
//no.4
Console.WriteLine("Question 4\n" + name + ",what is the tallest mountain in the world?\na.Everest\nb.Fuji\nc.Bromo\n");
ansr4 = Console.ReadLine();
Console.Clear();
if (ansr4 == "a")
{
score = score + 1;
Console.WriteLine("Correct\n" + name + "'s score:" + score + "\n");
}
else
{
Console.WriteLine("Wrong\n" + name + "'s score:" + score + "\n");
}
Console.Beep(900, 1500);
Console.Clear();
//no.5
Console.WriteLine("Question 3\n" + name + ",If you were in third place and you over take someone in second place what place would you be in now?\na.first\nb.second\nc.third\n");
ansr5 = Console.ReadLine();
Console.Clear();
if ((ansr5 == "b") && (score == 4))
{
//bonus level
Console.WriteLine("Congratulations" + name + "you have scored a perfect 5!\nWould you like to enter the bonus stage?\nIf you lose this you lose the game\nbut if you pass you will receive 5 points.\nYes, or No?");
bonus1 = Console.ReadLine();
if (bonus1 == "yes")
{
}
else
{
Console.WriteLine();
}
}
else if (ansr5 == "b")
{
score = score + 1;
Console.WriteLine("Correct\n" + name + "'s score:" + score + "\n");
}
else
{
Console.WriteLine("Wrong\n" + name + "'s score:" + score + "\n");
}
Console.Beep(1000, 1500);
Console.Clear();
Console.ReadKey();
}
}
我创建了一个多选 C# 控制台程序,我放置了一个奖励阶段,如果您获得完美的 5 分,该阶段就会触发,但当它达到它时,什么也没有显示。 为什么? 所有其他如果工作除了奖金有人可以告诉我如何解决这个问题吗? 对不起,如果我的编码很新手 (int,string,if)
{
int score = 0;
string ansr1 = "";
string ansr2 = "";
string ansr3 = "";
string ansr4 = "";
string ansr5 = "";
string bonus1 = "";
Console.WriteLine("Welcome to my quiz user!(please type your'e answers in lower case letters)\nWhat is your'e name?\n");
string name = Console.ReadLine();
Console.Clear();
Console.WriteLine("Okay "+name+" lets start!\n");
Console.Beep(500, 500);
Console.Beep(500, 500);
Console.Beep(500, 500);
Console.Beep(660, 2500);
Console.Clear();
//no.1
Console.WriteLine("Question 1\nWhat colour is the sky "+name+"?\na.blue\nb.green\nc.red\n");
ansr1 = Console.ReadLine();
Console.Clear();
if (ansr1 == "a")
{
score = score + 1;
Console.WriteLine("Correct!\n"+name+"'s score:"+score+"\n");
}
else
{
Console.WriteLine("Wrong!\n"+name+"'s score:"+score+"\n");
}
Console.Beep(600, 1500);
Console.Clear();
//no.2
Console.WriteLine("Question 2\nHow many stars are there on the american flag "+name+"?\na.21\nb.72\nc.50\n");
ansr2 = Console.ReadLine();
Console.Clear();
if (ansr2 == "c")
{
score = score+1;
Console.WriteLine("Correct\n"+name+"'s score:"+ score+"\n");
}
else
{
Console.WriteLine("Wrong\n"+name+"'s score:"+score+"\n");
}
Console.Beep(700, 1500);
Console.Clear();
//no.3
Console.WriteLine("Question 3\n"+name+",If you were in third place and you over take someone in second place what place would you be in now?\na.first\nb.second\nc.third\n");
ansr3 = Console.ReadLine();
Console.Clear();
if (ansr3 == "b")
{
score = score+1;
Console.WriteLine("Correct\n"+name+"'s score:" + score+"\n");
}
else
{
Console.WriteLine("Wrong\n"+name+"'s score:" + score+"\n");
}
Console.Beep(800, 1500);
Console.Clear();
//no.4
Console.WriteLine("Question 4\n" + name + ",what is the tallest mountain in the world?\na.Everest\nb.Fuji\nc.Bromo\n");
ansr4 = Console.ReadLine();
Console.Clear();
if (ansr4 == "a")
{
score = score + 1;
Console.WriteLine("Correct\n" + name + "'s score:" + score + "\n");
}
else
{
Console.WriteLine("Wrong\n" + name + "'s score:" + score + "\n");
}
Console.Beep(900, 1500);
Console.Clear();
//no.5
Console.WriteLine("Question 3\n" + name + ",If you were in third place and you over take someone in second place what place would you be in now?\na.first\nb.second\nc.third\n");
ansr5 = Console.ReadLine();
Console.Clear();
if ((ansr5 == "b") && (score == 5))
{
//bonus level
Console.WriteLine("Congratulations" + name + "you have scored a perfect 5!\nWould you like to enter the bonus stage?\nIf you lose this you lose the game\nbut if you pass you will receive 5 points.\nYes, or No?");
bonus1 = Console.ReadLine();
if (bonus1 == "yes")
{
}
else
{
Console.WriteLine();
}
}
else if (ansr5 == "b")
{
score = score + 1;
Console.WriteLine("Correct\n" + name + "'s score:" + score + "\n");
}
else
{
Console.WriteLine("Wrong\n" + name + "'s score:" + score + "\n");
}
Console.Beep(1000, 1500);
Console.Clear();
Console.ReadKey();
}
}
}
您在查看分数==5 的奖金时,您的最佳分数只能是 4。我想你忘了在第五个问题后增加分数。您必须在第 5 个问题后检查 score==4 或 increment score。这是更新的代码。
{
int score = 0;
string ansr1 = "";
string ansr2 = "";
string ansr3 = "";
string ansr4 = "";
string ansr5 = "";
string bonus1 = "";
Console.WriteLine("Welcome to my quiz user!(please type your'e answers in lower case letters)\nWhat is your'e name?\n");
string name = Console.ReadLine();
Console.Clear();
Console.WriteLine("Okay "+name+" lets start!\n");
Console.Beep(500, 500);
Console.Beep(500, 500);
Console.Beep(500, 500);
Console.Beep(660, 2500);
Console.Clear();
//no.1
Console.WriteLine("Question 1\nWhat colour is the sky "+name+"?\na.blue\nb.green\nc.red\n");
ansr1 = Console.ReadLine();
Console.Clear();
if (ansr1 == "a")
{
score = score + 1;
Console.WriteLine("Correct!\n"+name+"'s score:"+score+"\n");
}
else
{
Console.WriteLine("Wrong!\n"+name+"'s score:"+score+"\n");
}
Console.Beep(600, 1500);
Console.Clear();
//no.2
Console.WriteLine("Question 2\nHow many stars are there on the american flag "+name+"?\na.21\nb.72\nc.50\n");
ansr2 = Console.ReadLine();
Console.Clear();
if (ansr2 == "c")
{
score = score+1;
Console.WriteLine("Correct\n"+name+"'s score:"+ score+"\n");
}
else
{
Console.WriteLine("Wrong\n"+name+"'s score:"+score+"\n");
}
Console.Beep(700, 1500);
Console.Clear();
//no.3
Console.WriteLine("Question 3\n"+name+",If you were in third place and you over take someone in second place what place would you be in now?\na.first\nb.second\nc.third\n");
ansr3 = Console.ReadLine();
Console.Clear();
if (ansr3 == "b")
{
score = score+1;
Console.WriteLine("Correct\n"+name+"'s score:" + score+"\n");
}
else
{
Console.WriteLine("Wrong\n"+name+"'s score:" + score+"\n");
}
Console.Beep(800, 1500);
Console.Clear();
//no.4
Console.WriteLine("Question 4\n" + name + ",what is the tallest mountain in the world?\na.Everest\nb.Fuji\nc.Bromo\n");
ansr4 = Console.ReadLine();
Console.Clear();
if (ansr4 == "a")
{
score = score + 1;
Console.WriteLine("Correct\n" + name + "'s score:" + score + "\n");
}
else
{
Console.WriteLine("Wrong\n" + name + "'s score:" + score + "\n");
}
Console.Beep(900, 1500);
Console.Clear();
//no.5
Console.WriteLine("Question 3\n" + name + ",If you were in third place and you over take someone in second place what place would you be in now?\na.first\nb.second\nc.third\n");
ansr5 = Console.ReadLine();
Console.Clear();
if ((ansr5 == "b") && (score == 4))
{
//bonus level
Console.WriteLine("Congratulations" + name + "you have scored a perfect 5!\nWould you like to enter the bonus stage?\nIf you lose this you lose the game\nbut if you pass you will receive 5 points.\nYes, or No?");
bonus1 = Console.ReadLine();
if (bonus1 == "yes")
{
}
else
{
Console.WriteLine();
}
}
else if (ansr5 == "b")
{
score = score + 1;
Console.WriteLine("Correct\n" + name + "'s score:" + score + "\n");
}
else
{
Console.WriteLine("Wrong\n" + name + "'s score:" + score + "\n");
}
Console.Beep(1000, 1500);
Console.Clear();
Console.ReadKey();
}
}