99 015
Assignments Done
98.9%
Successfully Done
In May 2021

# Answer to Question #27706 in C++ for red rose

Question #27706
write a program to input 5 integer numbers in an array. As each number is input, add the numbers to a total. After all numbers are input, display the numbers, their total, and their average.
1
2013-04-09T11:10:13-0400
#include <iostream>

using namespace std;

void input_array(int* array, int arraySize)
{
cout << "Input an array of " << arraySize << " elements: ";
for (int c = 0; c < arraySize; c++)
cin >> array[c];
}

int calc_total(int* array, int arraySize)
{
int result = 0;
for (int c = 0; c < arraySize; c++)
result += array[c];
return result;
}

float calc_average(int* array, int arraySize)
{
return calc_total(array, arraySize) * 1.0 / arraySize;
}

void print_array(int* array, int arraySize)
{
cout << "Array elements:";
for (int c = 0; c < arraySize; c++)
cout << " " << array[c];
cout << endl;
}

int main()
{
int array[5];
input_array(array, 5);
print_array(array, 5);
cout << "The sum of array elements is: "
<< calc_total(array, 5) << endl;
cout << "The average value of array elements is: "
<< calc_average(array, 5) << endl;
return 0;
}

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!