i have just started my first c# class and have an assignement. what i need to do is build a program that lets a user input 5 test scores then it displays your letter grade based on the average. my teacher hasnt responded in a week so im relying on your help. i seem to have the program accepting and storing the 5 test scores. im not sure if the average is "actually" being calculated. i am sure though that the average is not being applied to the switch statement. when the program runs and returns the grade letter its blank not displaying the default either.
my thought is i just need a simple line in the program to initiate the grade letter test and then store the letter for string grade. something like:
myTest.SetGrade(); // to initiate the test then
Console.WriteLine("Grade: ", myTest.Grade) // to show the letter but thats not happening
i will attach a zip of my current visual studio code if that is of use and i will copy it below.
I cant express enough how grateful i am for your help, i have spend hours online and in my book and am getting no where
using System;
namespace TicketSpace
{
public class Test
{
private int exam1;
private int exam2;
private int exam3;
private int exam4;
private int exam5;
private int average;
private string grade;
public Test()
{
}
public Test(int test1, int test2,int test3,int test4,int test5)
{
It looks like you're not setting the grade value after you get the average of the exams with the call to myTest.DetermineAverage().
Also, there's an error in your format string argument in the call to Console.WriteLine("Grade: ", myTest.Grade); It should be Console.WriteLine("Grade: {0}", myTest.Grade);
Last edited by RaleTheBlade; March 9th, 2011 at 05:12 PM.
R.I.P. 3.5" Floppy Drives
"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein
It looks like you're not setting the grade value after you get the average of the exams with the call to myTest.DetermineAverage().
Also, there's an error in your format string argument in the call to Console.WriteLine("Grade: ", myTest.Grade); It should be Console.WriteLine("Grade: {0}", myTest.Grade);
thanks for the reply
to confirm what you mean about setting the value are you saying this....
public string Grade
{
get
{
return grade;
}
}
should be changed to this...???
public string Grade
{
get
{
return grade;
}
set
{
grade = value;
}
}
and are you also saying instead of having:
Console.WriteLine("Grade: ", myTest.Grade)
it should be:
Console.WriteLine("Grade: {0}", myTest.Grade);
just wanna make sure i understand clearly what is needed thanks!
to confirm what you mean about setting the value are you saying this....
public string Grade
{
get
{
return grade;
}
}
should be changed to this...???
public string Grade
{
get
{
return grade;
}
set
{
grade = value;
}
}
and are you also saying instead of having:
Console.WriteLine("Grade: ", myTest.Grade)
it should be:
Console.WriteLine("Grade: {0}", myTest.Grade);
just wanna make sure i understand clearly what is needed thanks!
Ehhh... not quite. Just adding a set accessor to the Grade property isn't going to solve your problem You still need to determine the grade letter using the average you get from a call to DetermineAverage(). Your SetGrade() method does a good job of converting the average to a letter grade, so stick with that.
Just call the SetGrade() method and pass in the test average after you call DetermineAverage() and you should be set.
Last edited by RaleTheBlade; March 10th, 2011 at 12:13 PM.
R.I.P. 3.5" Floppy Drives
"I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.