Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago