76 409
Assignments Done
Successfully Done
In May 2019

Answer to Question #32257 in C++ for Jeremy Spackman

Question #32257
I need help with a program, but i cant seem to get arrays into the subprograms/subfunctions.

Input a list of positive numbers (terminated 0) in to an array, find the mean (average) of the numbers in the array, and output the results. Use a subprogram to input the numbers, a function to find the mean, and a subprogram to output the results.
Expert's answer
#include <iostream>
using namespace std;

void read_array(double *arr) {
cout << "Input array of numbers(terminated 0):" << endl;
double n;
do {
cin >> n;
*arr = n;
} while (n != 0);

double get_mean(double *arr) {
double sum = 0;
int cnt = 0;
while (*arr != 0) {
sum += *arr;
return sum / cnt;

void write_mean(double d) {
cout << "The mean is " << d << endl;

int main() {
double arr[1000];

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!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions