Final answer:
To find the average of 5 students using C++ functions, you can create a function that calculates the average by summing up the grades and dividing by 5. The program can prompt the user to enter the grades of the 5 students and then call the function to calculate the average.
Step-by-step explanation:
To write a C++ program to find the average of 5 students using functions, you can create a function called 'calculateAverage' that takes an array of 5 student grades as input and returns the average. Within this function, you can use a for loop to iterate through the array and calculate the sum of the grades. Finally, you can divide the sum by 5 to get the average and return it.
#include
using namespace std;
double calculateAverage(int grades[])
{
double sum = 0;
for (int i = 0; i < 5; i++)
{
sum += grades[i];
}
return sum / 5;
}
int main()
{
int grades[5];
cout << "Enter the grades of 5 students:" << endl;
for (int i = 0; i < 5; i++)
{
cin >> grades[i];
}
double average = calculateAverage(grades);
cout << "The average of the 5 students is: " << average << endl;
return 0;
}