In: Computer Science
Create a program that calculates the average of 3 test scores. Make use of an array to store the integer scores.
const int size = 3; int testScores[size];
Send this array to a function that actually calculates and returns the average.
1. Tell the user what the program does.
2. Prompt the user to enter the integer scores. ( Use a for
loop to do this. )
3. Create and implement a function with prototype:
double average( int a[], int size);
4. Output the results in the main function.
5. Ask the user if he wishes to run the program again.
// I need help fixing my code, it might be a math error
//c++ code
#include <iostream>
using namespace std;
//Function Prototypes
bool runAgain(void);
double average(int a[], int size);
int main() {
//Make an array of .....
const int size = 3;
int testScores[size];
cout << "This program calcuates and returns
the average of 3 test scores!" << endl;
do {
//User to populate the array
for (int i = 0; i < size; i++)
{
cout <<
"Enter a score: ";
cin >>
testScores[i];
}
cout << endl;
cout << average(testScores, size) << endl;
} while (runAgain());
}
// Function Impplementation
double average(int a[], int size) {
for (int i = 0; i < size; i++) {
return a[i] / size;
}
}
bool runAgain(void) {
char
userResponse;
cout <<
"\nWould you like to run again (y or n): ";
cin >>
userResponse;
cin.ignore(); //
to clean up the input stream
if
(userResponse == 'y' || userResponse == 'Y')
return(true);
return(false);
}
#include <iostream>
using namespace std;
//Function Prototypes
bool runAgain(void);
double average(int a[], int size);
int main() {
const int size = 3;
int testScores[size];
cout << "This program calcuates and returns the average of 3 test scores!" << endl;
do {
//User to populate the array
for (int i = 0; i < size; i++) {
cout << "Enter a score: ";
cin >> testScores[i];
}
cout << endl;
cout << average(testScores, size) << endl;
} while (runAgain());
}
// Function Impplementation
double average(int a[], int size) {
double sum=0;
for (int i = 0; i < size; i++) {
sum+=a[i];
}
return sum/size;
}
bool runAgain(void) {
char userResponse;
cout << "\nWould you like to run again (y or n): ";
cin >> userResponse;
cin.ignore(); // to clean up the input stream
return (userResponse == 'y' || userResponse == 'Y');
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME