Hi there, I have been given this question to complete but I can't seem
to get my code working properly. I'm very new to C# so sorry if i come
across as stupid!

Here is the question...

Create a class that represents the grade distribution for a given
course. In this class you should write methods to perform
the following tasks:


· Read in and count the lettered grades A, B, C, D and F as they are
entered by the user
· Return the total number of grades entered
· Return the percentage of each letter grade as a whole number between
0 and 100 inclusive
· Draw a bar graph of the grade distribution


The graph should have five bars, one per grade. Each bar can be a
horizontal row of asterisks, such that the number of
asterisks in a row is proportionate to the percentage of grades in
each category. For example, let one asterisk represent
2%, so 50 asterisks correspond to 100%. Mark the horizontal axis at
10% increments from 0 to 100% and label each line
with a letter grade.


Heres my code so far...

using System;

class Program
{
int a, b, c, d, e, f;
int aCount;
int bCount;
int cCount;
int dCount;
int fCount;

public static void Main(string[] args)
{
    Program newProgram = new Program();

newProgram.aCount = 0;
newProgram.bCount = 0;
newProgram.cCount = 0;
newProgram.dCount = 0;
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 = (newProgram.aCount / totalGrades) * 100;
newProgram.b = (newProgram.bCount / totalGrades) * 100;
newProgram.c = (newProgram.cCount / totalGrades) * 100;
newProgram.d = (newProgram.dCount / totalGrades) * 100;
newProgram.f = (newProgram.fCount / totalGrades) * 100;

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("*");
}
}
}


Hope you can help

Many Thanks

Reply via email to