Need help writing code
What would you write to allow a student to enter a student id and three exam scores then return the exam average? I know how to write the last part. Im guessing id use a get command to allow the student to enter id and exam scores but Idk how to structure it. Any help would be great! thanks
Cameron WardPosted Jul 16, 2011, 4:57 PM
Zoran HorvatPosted Jul 16, 2011, 4:45 PM
using System;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter student id: ");
string studentId = Console.ReadLine();
Console.WriteLine("Enter three student's marks (0-100%):");
int sum = 0;
for (int i = 0; i < 3; i++)
{
string line = Console.ReadLine();
int currentMark = int.Parse(line);
sum += currentMark;
}
int average = sum / 3;
string mark = null;
if (average < 35)
mark = "E";
else if (average < 50)
mark = "D";
else if (average < 60)
mark = "C";
else if (average < 70)
mark = "B2";
else if (average < 80)
mark = "B1";
else if (average < 90)
mark = "A2";
else
mark = "A1";
Console.WriteLine("Average mark for student {0} is {1}% ({2})", studentId, average, mark);
Console.WriteLine("Press ENTER to continue...");
Console.ReadLine();
}
}
}
And here is the sample input/output:
Enter student id: 14
Enter three student's marks (0-100%):
56
29
86
Average mark for student 14 is 57% (C)
Press ENTER to continue...
Zoran