代码
int count = 0; string answer = ""; int i = 0;
for (i = 1; i <= 5; i++)
{
Console.Write("继续玩下一局吗?(y/n)");
answer = Console.ReadLine();
if (answer == "n")
{
Console.Write("您已经中途退出程序了");
i--;
}
else if (answer == "y")
{
Console.Write("您正在玩第{0}局,成绩为:", i);
int score = Convert.ToInt32(Console.ReadLine());
if (score > 80)
{
count++;
}
}
else
{
Console.WriteLine("输入有误,请重新输入!");
}
}
if (i >= 5)
{
double rate = count / 5;
if (rate > 0.8)
{
Console.WriteLine("恭喜,通过一级");
}
else if (rate > 0.6)
{
Console.WriteLine("恭喜,通过二级");
}
else
{
Console.WriteLine("\n对不起,你未能晋级,继续加油吧~");
}
}
else
{
Console.WriteLine("对不起,你没有完成游戏,不能晋级,继续加油努力");
}
Console.WriteLine("游戏结束!");
效果
image.png