Answer to Question #350043 in C++ for fiona

Question #350043

create a c++ program with a function named average that calculates the average of the students 5 SCORES using array. Let the student enter the scores in the main function and the function average will calculate the average.


1
Expert's answer
2022-06-13T08:27:05-0400
#include <iostream>
using namespace std;

int average(int* scores);

int main()
{
    int scores[5];
    cout << "Enter 1st score: ";
    cin >> scores[0];
    cout << "Enter 2nd score: ";
    cin >> scores[1];
    cout << "Enter 3rd score: ";
    cin >> scores[2];
    cout << "Enter 4th score: ";
    cin >> scores[3];
    cout << "Enter 5th score: ";
    cin >> scores[4];
    cout << "\nAverage: " << average(scores) << endl;
}

int average(int* scores) {
    return (scores[0] + scores[1] + scores[2] + scores[3] + scores[4]) / 5;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS