Question: Create a program in C++ which allows users to enter student grades (whole numbers) until the user enters a negative one. Average the numbers entered

Create a program in C++ which allows users to enter student grades (whole numbers) until the user enters a negative one. Average the numbers entered but do not include the -1 in the average (but you knew that already!) Be sure to have at least one function.

** This is the code that I have written so far. I know it needs a few tweaks to work correctly:

#include // STD IO Stream Library, Keyboard and Terminal Window

#include // C++ Mathematical Libraries

using namespace std;

float grade_average(int); // Prototype for the Grade_Entry Function

int main()

{

system("Color 0A"); // Lime Green on Black Display

int grades; // Grades Declared as an Integer Value

cout << "Please Enter Student Grades, to the Nearest Whole Number: " << endl << endl;

// Prompt User to Enter Student Grades to the Nearest Whole Number

do // Keep Doing...

{

cin >> grades; // User Enters Grades

}

while (grades != -1); // ... until a Negative One is Entered

cout << endl;

float result = grade_average(grades); // Grade_Average Function Call

cout << "The Average of the Grades Is: " << result << endl;

system("pause");

return 0;

}

float grade_average(int values) // Grade_Entry Function Definition

{

int i; // Indexing Variable Declared as an Integer Value

int sum = 0; // Sum Declared as an Integer and Initialized to Zero

for (i = 1; i < values; i++)

{

sum += values; // Add Each Value Entered

}

float average = sum / i;

return average;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!