Question

In: Computer Science

Create a program that calculates the average of 3 test scores. Make use of an array...

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);
       }

Solutions

Expert Solution

#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


Related Solutions

Create a C++ program which will accept an unlimited number of scores and calculates the average...
Create a C++ program which will accept an unlimited number of scores and calculates the average score. You will also need to prompt for the total points possible. Assume each test is worth 100 points. Requirements. • Enter the Student ID first, then prompt for grades. Keep prompt- ing for grades until the client enters ’calc’. That triggers final pro- cessing. • Make your code as reliable as possible. • Make your program output easy to read. • You cannot...
Create a program in java that calculates area and perimeter of a square - use a...
Create a program in java that calculates area and perimeter of a square - use a class and test program to calculate the area and perimeter; assume length of square is 7 ft.
Write a program that calculates the average of a four lab marks. It should use the...
Write a program that calculates the average of a four lab marks. It should use the following functions: • void getMarks() should ask the user for a lab marks, store it in a reference parameter variable, and validate it so that lab marks lower than 0 or higher than 100 is not accepted. This function should be called by main once for each of the four lab marks to be entered. • void avgGradeDisp() should calculate and display the average...
Create a C++ program that will ask the user for how many test scores will be...
Create a C++ program that will ask the user for how many test scores will be entered. Setup a while loop with this loop iteration parameter. (no fstream) The data needs to include the student’s first name, student number test score the fields should be displayed with a total width of 15. The prompt should be printed with a header in the file explaining what each is: ex. First Name student number Test Score 1) mike 6456464   98 2) phill...
(JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students...
(JAVA) Write a program that maintains student test scores in a two-dimesnional array, with the students identified by rows and test scores identified by columns. Ask the user for the number of students and for the number of tests (which will be the size of the two-dimensional array). Populate the array with user input (with numbers in {0, 100} for test scores). Assume that a score >= 60 is a pass for the below. Then, write methods for: Computing the...
Create a C++ program that makes use of both concepts i.e. Array of structure and array...
Create a C++ program that makes use of both concepts i.e. Array of structure and array within the structure by using the following guidelines: 1. Create an Array of 5 Structures of Student Records 2. Each structure must contain: a. An array of Full Name of Student b. Registration Number in proper Format i.e 18-SE-24 c. An array of Marks of 3 subjects d. Display that information of all students in Ascending order using “Name” e. Search a particular student...
Write a program using multiple functions. Make use of an array to store data Make use...
Write a program using multiple functions. Make use of an array to store data Make use of searching techniques Read data from a file Write data to a file Instructions: In this lab, you will be examining a set of stock collected over a twenty four day period. Be sure to make use of an array to store these stocks. You will be required to read in the data points from a file. Write a function to read in the...
Write a program that calculates the mean, median and mode of a given array in the...
Write a program that calculates the mean, median and mode of a given array in the following manner: i) Write three functions mean (), median () and mode () that calculates the mean, median and mode of an array. ii) Using these functions write a program that calculates all the three above mentioned values for two different arrays A and B where A is an array that contains the number of hours spent by a person each day for playing...
Consider the following program. // This program averages 3 test scores. It repeats as // many...
Consider the following program. // This program averages 3 test scores. It repeats as // many times as the user wishes. #include <iostream> using namespace std; int main() { int score1, score2, score3; // Three scores double average; // Average score char again; // To hold Y or N input do { // Get three scores. cout << "Enter 3 scores and I will average them: "; cin >> score1 >> score2 >> score3; // Calculate and display the average....
ITP100 Project: Part 3 Create the pseudocode solution to a program that calculates the final score...
ITP100 Project: Part 3 Create the pseudocode solution to a program that calculates the final score and letter grade for one student. Please use the following grading system: 9 Homework Assignments – 100 points each 10 points 11 Quizzes – 100 points each 5 points 5 Projects – 100 points each 10 points 6 Discussion posts – 100 points each 10 points 4 Exams – 100 points each 65 points A = 90 – 100% B = 80 – 89%...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT