need help with counter and accumulators

This is a discussion on need help with counter and accumulators within the C++ Programming forums, part of the General Programming Boards category; This one is a review for a final exam which I will be taking in about 8 hours. Supposively, my ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    5

    need help with counter and accumulators

    This one is a review for a final exam which I will be taking in about 8 hours. Supposively, my instructor insist that if we can do this program we should be able to do the final. I'm big in trouble. I started the program but I'm stumped. I just started back attending my classes 2 1/2 weeks ago after being out for 8 weeks ( was put on bed rest by doctor due to complication with pregnancy). Should've withdrew from my classes, but I didn't so now I'm trying to catchup on what I missed in four classes and attempt to take the finals. The only thing that my program does is displays the number of all grades entered including valid and non valid. I need it to display total number of grades included in the average; the average grade; and total number of As, Bs, Cs, Ds, and Fs. Right now it displays the average but the average includes grades of 0 which it shouldn't.
    Would someone please advise me on what to do. I really want to know how to count the number of letter grades. I missed so much of class and am very lost, tired, and stressed out. I hope I don't go into early labor over this class. I've included a copy of the program description and the code that I have so far.

    PROGRAM DESCRIPTION

    You task is to write an interactive program that determines a students letter grade from the numeric grade (an integer), computes the average of all valid grades entered, and displays statistics about the grades entered.

    SPECIFIC DIRECTIONS

    Ask the user for one numeric grade at a time, and display the appropriate letter grade. You must use a separate function to request and input the grade, then return the grade to main.

    The numeric ranges for grades are as follows:

    91 100: A
    81 90: B
    71 80: C
    65 70: D
    Below 65: F

    Use another function to test the numeric grade and return the letter equivalent to main .

    You need to determine the average of all valid grades entered: any nonzero grade is valid, but any grades of zero should not be included in the average, since this means the student didnt even take the test (you get 2 points for writing your name!). So, you dont want to lower the average by including grades of . When the user wants to quit, display the following: total number of all grades entered, including valid grades and grades of ; total number of grades included in the average; the average grade; and total number of As, Bs, Cs, Ds, and Fs.

    Program
    __________________________________________________
    Code:
    #include <iostream>
    using namespace std;
    
    //function prototypes
    int getAvgGrade();
    char assignGrade(float);
    
    int main()
    {
    
    //declare variables
    _______________________________________
    char grade = ' ';
    float n_grade = 0.0;
    float total_n_grade= 0.0;
    float avg =0.0;
    //get average grade
    n_grade = getAvgGrade();
    //assign grade
    grade = assignGrade(n_grade);
    //display grade
    cout << "Average Grade: " << grade << endl;
    
    
    return 0;
    } //end of main function
    
    //*****program-defined functions*****
    int getAvgGrade()
    {
    
    //gets and accumulates the scores, then returns the average
    
    int total_n_grade = 0;
    int total_grades = 0;
    float n_grade = 0.0;
    char letterGrade = ' ';
    char grade = ' ' ;
    cout << "Pleae enter the first numeric grade: ";
    cin >> n_grade;
    
    while (n_grade > 0)
    {
    
    total_grades = total_grades + 1;
    
    total_n_grade = total_n_grade + n_grade;
    
    cout << "please enter the next numeric grade: ";
    cin >> n_grade;
    
    }//end while
    if (total_grades >=0)
    n_grade = total_n_grade/ total_grades;
    cout << "Total number of all grades entered: " << total_grades << endl;
    
    return n_grade;
    
    } //end of getAvGrade function
    
    
    char assignGrade(float n_grade)
    {
    //assigns the letter grade
    char letterGrade = ' ';
    
    if (n_grade>= 91)
    letterGrade = 'A';
    else if (n_grade >= 81)
    letterGrade = 'B';
    else if (n_grade >= 71)
    letterGrade = 'C';
    else if (n_grade >= 65)
    letterGrade = 'D';
    else letterGrade = 'F';
    //end ifs 
    return letterGrade;
    } //end of assignGrade function
    &#91;code]&#91;/code]tagged by Salem

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Post a specific question.

    Kuphryn

  3. #3
    Registered User datainjector's Avatar
    Join Date
    Mar 2002
    Posts
    356
    Originally posted by kuphryn
    Post a specific question.

    Kuphryn
    HA Kuphryn have a slow internet connection Cborad..
    "I wish i could wish my wishs away"

    "By indirections find directions out" -- William Shakespears

    "Do what thou wilt shall be the whole of the law" -- Crowley "THE BEAST 666"

    Mizra -> love = Death...
    RDB(Rocks yooo)..

    http://www.cbeginnersunited.com

    Are you ready for the Trix ???

  4. #4
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > HA Kuphryn have a slow internet connection Cborad..
    What does that have to do with anything?
    If you're making fun of somebody's slow internet connection, do that in a PM, please.
    The world is waiting. I must leave you now.

  5. #5
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    It's a very long post, if you can ask specefic questions, it will be easier to answer them.
    none...

  6. #6
    Spanky devour89's Avatar
    Join Date
    Nov 2002
    Posts
    148
    I cant even be bothered to read it.

    Give us a specific question even though i think its to late now!
    Dev C++
    Win XP/2k/98

    I DO NOT TAKE CLASSES I DONT GET HOMEWORK THIS IS NOT A HOMEWORK QUESTION!!!

    He's lean he's keen... He's the spank machine!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Grades program has me lost
    By adrea in forum C++ Programming
    Replies: 3
    Last Post: 12-14-2002, 07:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21