Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a C++ project that allows the user to enter the number of points a person earns playing a game for each of five days.

Create a C++ project that allows the user to enter the number of points a person earns playing a game for each of five days. Store the daily points in a five element array named points. Then display the contents of the array on the computer screen using a function called displayArray.

You also have to calculate the total and the average by adding another program-defined function to the points program. The additional function will be a value-returning function called get-Average. The function will calculate the average number of points earned for the 5 days and then return the result to the main function.

Program requirements:

You will have 2 functions in the program:

//function prototypes

void displayArray(int points[], int numElements);

double getAverage(int points[], int numElements);

**** I tried this program, but I could not get it to work, because it said that [days] did not evaluate to a constant & that the espression must have a constant value.

#include

using namespace std;

//function prototypes

void displayArray(int points[], int numElements);

double getAverage(int points[], int numElements);

int main()

{

//declaring necessary variables

int days = 5;

int points[days];

//taking inputs

for (int i = 0; i

{

cout << "Enter the number of points of day " << i + 1 << ": ";

cin >> points[i];

}

//display the contents of array

displayArray(points, days);

//calling function to get average value

double avg = getAverage(points, days);

//display total and average points

cout << "The total number of points earned for " << days << " days: ";

cout << avg*days << endl;

cout << "The average number of points earned for " << days << " days: ";

cout << avg << endl;

return 0;

}

void displayArray(int points[], int numElements)

{

cout << " The contents of the array: ";

for (int i = 0; i

{

cout << points[i] << " ";

}

cout << endl;

}

double getAverage(int points[], int numElements)

{

//computing total points

int sum = 0;

for (int i = 0; i

sum += points[i];

//computing average value

double avg = (double)sum / numElements;

return avg;//returning 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

Students also viewed these Databases questions