Community discussion forum

Help please for student

  • 11 months ago
    Please can someone tell me how I would add the following: if the grades are entered as 1A, 4B’s, 6C’s, 2D’s and 1F, then the output would look like: 0 10 20 30 40 50 60 70 80 90 100 | | | | | | | | | | | ************************************************** **** A ************** B ********************* C ****** D **** F as code into this: using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 { class Program { double a, b, c, d, f; int aCount, bCount, cCount, dCount, fCount; private void GradeCheck(string MyGrade) { try { int Grade = Convert.ToInt32(MyGrade); if (Grade <= 50) fCount++; else if (Grade > 50 && Grade <= 70) dCount++; else if (Grade > 70 && Grade <= 80) cCount++; else if (Grade > 80 && Grade <= 90) bCount++; else if (Grade >= 90) aCount++; } catch { Console.WriteLine("Not a valid grade!"); } } public static void Main(string[] args) { Program newProgram = new Program(); newProgram.aCount = newProgram.bCount = newProgram.cCount = newProgram.dCount = newProgram.fCount = 0; string myGrade = ""; while (myGrade != "END") { Console.WriteLine("Please enter a grade:"); myGrade = Convert.ToString(Console.ReadLine().ToUpper()); Console.WriteLine("\t{0}", myGrade); newProgram.GradeCheck(myGrade); } int totalGrades = newProgram.aCount + newProgram.bCount + newProgram.cCount + newProgram.dCount + newProgram.fCount; newProgram.a = (Convert.ToDouble(newProgram.aCount) / totalGrades) * 100.0; newProgram.b = (Convert.ToDouble(newProgram.bCount) / totalGrades) * 100.0; newProgram.c = (Convert.ToDouble(newProgram.cCount) / totalGrades) * 100.0; newProgram.d = (Convert.ToDouble(newProgram.dCount) / totalGrades) * 100.0; newProgram.f = (Convert.ToDouble(newProgram.fCount) / totalGrades) * 100.0; Console.WriteLine("A grades are equal to {0}%", newProgram.a); Console.WriteLine("B grades are equal to {0}%", newProgram.b); Console.WriteLine("C grades are equal to {0}%", newProgram.c); Console.WriteLine("D grades are equal to {0}%", newProgram.d); Console.WriteLine("F grades are equal to {0}%", newProgram.f); for (int i = 0; i < newProgram.aCount; i++) Console.Write("*"); for (int i = 0; i < newProgram.bCount; i++) Console.Write("*"); for (int i = 0; i < newProgram.cCount; i++) Console.Write("*"); for (int i = 0; i < newProgram.dCount; i++) Console.Write("*"); for (int i = 0; i < newProgram.fCount; i++) Console.Write("*"); Console.ReadLine(); } } }
    Post was edited on 02/12/2008 18:04:11 Report abuse

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Want to stay in touch with what's going on? Follow us on twitter!