I have a program that is suppose to display the corresponding letter grade A,B,C,D,E. Instead is prints the numeric value. I classified it as a decimal because I did not know what you classify text under. How do I fix this?
private void CalculateButton_Click(object sender, EventArgs e)
{
decimal Score = 0 , Percent, Average = 0, Letter = 0, GrandTotal = 0;
if (NameTextBox.Text != "" && ScoreTextBox.Text != "")
{
if (Score >= 0 && Score <= 150)
{
Score = decimal.Parse(ScoreTextBox.Text);
Percent = Score / 150;
if (Score >= 90)
Letter = 'A';
else if (Score >= 80 && Score < 90)
Letter = 'B';
else if (Score >= 70 && Score < 80)
Letter = 'C';
else if (Score >= 60 && Score < 70)
Letter = 'D';
else if (Score < 60)
Letter = 'E';
GrandTotal += 1;
Average += Score;
PercentTextBox.Text = Percent.ToString("P");
LetterGradeTextBox.Text = Letter.ToString();
GrandTotalTextBox.Text = Percent.ToString();
AverageTextBox.Text = Average.ToString("P");
}
else
MessageBox.Show("Score must be a positive number between 0 - 150");
}
else
MessageBox.Show("Name and a Score between 0 - 150 are required");
}
question from:
https://stackoverflow.com/questions/65907465/how-do-i-display-grade-letters 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…