在我的编程课介绍中,我们有一个额外的学分作业。我们需要让用户输入一个名字,他们参加了多少次测验,每个测验的成绩,然后计算平均值,然后计算他们的字母成绩。我现在拥有的是
namespace ConsoleApplication10
{
class Program
{
static void Main(string[] args)
{
int counter = 1;
Console.WriteLine("Name: ");
string sname = Console.ReadLine();
int numberOfQuizzes = 0;
while (sname != "Exit")
{
Console.WriteLine("Number of Quizzes: ");
string snumberOfQuizzes = Console.ReadLine();
numberOfQuizzes = int.Parse(snumberOfQuizzes);
while (counter - 1 < numberOfQuizzes)
{
Console.WriteLine("Quiz Score {0}", counter);
string sscore = Console.ReadLine();
counter++;
}
Console.WriteLine("Enter another name or type Exit to quit.");
sname = Console.ReadLine();
if (sname != "Exit")
{
Console.WriteLine("Number of Quizzes: ");
snumberOfQuizzes = Console.ReadLine();
while (counter - 1 < numberOfQuizzes) ;
}
}
}
}
}
第二次循环是不让用户输入他们参加了多少次测验。我也知道要给出分数,我需要一个 if/else,但是我会把它放在我的循环中的哪个位置?