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 A’s, B’s, C’s, D’s, and F’s. 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 student’s 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 didn’t even take the test (you get 2 points for writing your name!). So, you don’t 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 A’s, B’s, C’s, D’s, and F’s.
Program
__________________________________________________
[code][/code]tagged by SalemCode:#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