剛開始學習C#,我的問題是如何保持用戶輸入的記錄,以這樣的:score 1:
我如何爲每個用戶輸入號碼? C#
score 1: 98
score 2: 76
score 3: 65
score 4: 78
score 5: 56
在我的代碼可以輸入號碼,但不能似乎設置豈能順序我實現這個目標 我輸入:
98
76
65
78
56
代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyGrade03
{
public class Program
{
private int total; // sum of grades
private int gradeCounter; //number of grades entered
private int aCount; // Count of A grades
private int bCount; // Count of B grades
private int cCount; // Count of C grades
private int dCount; // Count of D grades
private int fCount; // Count of F grades
private string v;
public string CourseName { get; set; }
public Program(string name)
{
CourseName = name;
}
public void DisplayMessage()
{
Console.WriteLine("Welcome to the grade book for \n{0}!\n",
CourseName);
}
public void InputGrade()
{
int grade;
string input;
Console.WriteLine("{0}\n{1}",
"Enter the integer grades in the range 0-100",
"Type <Ctrl> z and press Enter to terminate input:");
input = Console.ReadLine(); //read user input
while (input != null)
{
grade = Convert.ToInt32(input); //read grade off user input
total += grade;// add grade to total
gradeCounter++; // increment number of grades
IncrementLetterGradeCounter(grade);
input = Console.ReadLine();
}
}
private void IncrementLetterGradeCounter(int grade)
{
switch (grade/10)
{
case 9: //grade was in the 90s
case 10:
++aCount;
break;
case 8:
++bCount;
break;
case7:
++cCount;
case6:
++dCount;
break;
default:
++fCount;
break;
}
}
public void DisplayGradeReport()
{
Console.WriteLine("\nGrade Report");
if (gradeCounter != 0)
{
double average = (double)total/gradeCounter;
Console.WriteLine("Total of the {0} grades entered is {1}",
gradeCounter, total);
Console.WriteLine("class average is {0:F}", average);
Console.WriteLine("{0}A: {1}\nB: {2}\nC: {3}\nD: {4}\nF: {5} ",
"Number of students who received each grade: \n",
aCount,
bCount,
cCount,
dCount,
fCount);
}
else
Console.WriteLine("No grades were entered");
}
static void Main(string[] args)
{
Program mygradebook = new Program(
"CS101 introduction to C3 programming");
mygradebook.DisplayMessage();
mygradebook.InputGrade();
mygradebook.DisplayGradeReport();
}
}
}
你不是你想要什麼明確的。做一點研究和努力,特別是在這個學校任務。 – EpicKip
有什麼你想要做的輸入序數?它只是一個索引,還是會用於任何事情? – Dave
@dave我只想知道我該如何得到分數1:每個輸入的數字 – jmike