使用 Visual Studio,这是一个练习,我需要添加其他学生,这不是问题。我的主要问题是:如果包含的值高于 100 或低于 0,我希望代码跳回输入问题,但我不知道检查(验证)用户输入的代码,任何帮助都会非常有帮助,我将非常感激。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Student_Marks_For_Statement
{
class Program
{
static void Main(string[] args)
{
char moreData;
double total = 0;
double secondTotal = 0;
for (double student1 = 0; student1 == 0; student1++)
{
Console.Write("Enter mark for student 1: ");
student1 = Convert.ToDouble(Console.ReadLine());
total += student1;
Console.WriteLine("Any more data? Enter 'y' or 'n' then return");
moreData = Convert.ToChar(Console.ReadLine());
if (moreData == 'n')
{
;
}
if (moreData == 'y')
{
Console.Write("Enter Value :");
secondTotal = Convert.ToDouble(Console.ReadLine());
total += secondTotal;
}
for (double student2 = 0; student2 == 0; student2++)
{
Console.Write("Enter mark for student 2: ");
student2 = Convert.ToDouble(Console.ReadLine());
total += student2;
student2++;
Console.WriteLine("Any more data? Enter 'y' or 'n' then return");
moreData = Convert.ToChar(Console.ReadLine());
if (moreData == 'n')
{
;
}
if (moreData == 'y')
{
Console.Write("Enter Value :");
secondTotal = Convert.ToDouble(Console.ReadLine());
total += secondTotal;
student2++;
} Console.WriteLine("Total marks = : {0}", total);
}
}
}
}
}