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
#include
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started