CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Mar 2011
    Posts
    2

    Please help very basic :)

    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)
    {

    exam1 = test1;
    exam2 = test2;
    exam3 = test3;
    exam4 = test4;
    exam5 = test5;

    }
    public void DetermineAverage( )
    {
    average = (exam1 + exam2 + exam3 + exam4 + exam5) / 5;
    }

    public string Grade
    {
    get
    {
    return grade;
    }
    }

    public void SetGrade(int average)
    {
    switch (average / 10)
    {
    case 9: grade = "A";
    break;
    case 8: grade = "B";
    break;
    case 7: grade = "C";
    break;
    case 6: grade = "D";
    break;
    default: grade = "F";
    break;

    }




    }

    }
    }

    NEXT CLASS


    using System;

    namespace TicketSpace
    {

    public class TestApp
    {
    static void Main( )
    {
    int exam1,
    exam2,
    exam3,
    exam4,
    exam5;




    exam1 = InputScore("Exam 1", out exam1);
    exam2 = InputScore("Exam 2", out exam2);
    exam3 = InputScore("Exam 3", out exam3);
    exam4 = InputScore("Exam 4", out exam4);
    exam5 = InputScore("Exam 5", out exam5);

    Test myTest = new Test(exam1, exam2, exam3, exam4, exam5);

    myTest.DetermineAverage();


    Console.WriteLine("Grade: ", myTest.Grade); // THIS IS WHERE THE PROGRAM ISNT DOING WHAT IT IS SUPPOSED TO.

    Console.ReadLine( );
    }


    public static int InputScore(string whichScore,
    out int s)
    {
    string inValue;

    Console.Write("Enter the {0}: ",
    whichScore);
    inValue = Console.ReadLine();
    s = Convert.ToInt32(inValue);
    return s;
    }


    }
    }
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured