Write a program that uses an array of string objects to hold the five student names, an array of five characters to hold the five students’ letter grades, and five arrays of four doubles to hold each student’s set of test scores.
The program should allow the user to enter each student’s name and his or her four test scores. It should then calculate and display each student’s average test score and a letter grade based on the average.
Input Validation: Do not accept test scores less than 0 or greater than 100.
1
Expert's answer
2016-04-26T11:43:06-0400
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;
namespace mark { class Program { static void Main(string[] args) { string[] name = new string[5]; char[] let = new char[5]; double[,] marks = new double[5,4]; double[] m = new double[5]; for (int i = 0; i < 5; i++) { Console.WriteLine("Enter name for "+ (i + 1) +" student"); name[i] = Console.ReadLine(); double sum = 0; for (int j = 0; j < 4; j++) {
Console.WriteLine("Enter "+ (j +1) + " mark for " + (i + 1) + " student"); do { marks[i, j] = Convert.ToDouble(Console.ReadLine()); } while (marks[i, j] < 0 || marks[i, j] > 100); sum += marks[i, j]; } m[i] = sum/4.0; if (sum/4.0 <= 100 && sum/4.0 >= 90) { let[i] = 'A'; } if (sum/4.0 <= 89 && sum/4.0 >= 82) { let[i] = 'B'; } if (sum/4.0 <= 81 && sum/4.0 >= 75) { let[i] = 'C'; } if (sum/4.0 <= 74 && sum/4.0 >= 67) { let[i] = 'D'; } if (sum/4.0 <= 66 && sum/4.0 >= 60) { let[i] = 'E'; } if (sum/4.0 <= 59 && sum/4.0 >= 0) { let[i] = 'F'; } } Console.WriteLine(); for (int i = 0; i < 5; i++) { Console.WriteLine(name[i] + " " + m[i] + " " + let[i]); } Console.ReadLine(); } } }
Comments
Leave a comment