public class Program { static void Main(string[] args) { Console.WriteLine("请输入第一个成绩:"); string str = Console.ReadLine(); { int[] intArr = new int[22]; for (int i = 0; i <= 22; i++) { } 我写到这里就不会写了,怎么能把我输入的数存进去呢 而且要求输入的数不超过十
static void Main(string[] args) { //int[] intArr = new int[22]; string str; int total = 0; for (int i = 1; i <= 22; i++) { Console.WriteLine("请输入第"+i+"个成绩:"); str = Console.ReadLine(); try { if (int.Parse(str) > 10) { Console.WriteLine("不能大于10"); Console.ReadLine(); } } catch (Exception ex) { Console.WriteLine("不是数字"); Console.ReadLine(); } total += int.Parse(str); if (i == 22) { Console.WriteLine("总成绩:" + total); Console.ReadLine(); } } }
修改这地方 if (i % 2 ==0) { Console.WriteLine("总成绩:" + total); Console.ReadLine(); }
{
static void Main(string[] args)
{
Console.WriteLine("请输入第一个成绩:");
string str = Console.ReadLine();
{
int[] intArr = new int[22];
for (int i = 0; i <= 22; i++)
{ }
我写到这里就不会写了,怎么能把我输入的数存进去呢 而且要求输入的数不超过十
static void Main(string[] args)
{
//int[] intArr = new int[22];
string str;
int total = 0;
for (int i = 1; i <= 22; i++)
{
Console.WriteLine("请输入第"+i+"个成绩:");
str = Console.ReadLine();
try
{
if (int.Parse(str) > 10) { Console.WriteLine("不能大于10"); Console.ReadLine(); }
}
catch (Exception ex) {
Console.WriteLine("不是数字"); Console.ReadLine();
}
total += int.Parse(str); if (i == 22)
{
Console.WriteLine("总成绩:" + total);
Console.ReadLine();
} }
}
{
Console.WriteLine("总成绩:" + total);
Console.ReadLine();
}