Answer to Question #21085 in C++ for Candice Battle

Question #21085
Input a list of positive numbers (terminated by 0) into an array, find the mean (average) of the numbers in the array, and output the result. Use a subprogram to input the numbers, a function to find the mean, and a subprogram to output the result.
1
Expert's answer
2012-12-24T09:58:42-0500

#include <iostream>
#include <conio.h>

using namespace std;


//main function
int main()
{
double number;
double arrayofnumber[1000];
cout<<"Enter number: ";
cin>>number;
int count=0;
while(number!=0){
cout<<"Enter number: ";
cin>>number;
arrayofnumber[count]=number;
count++;
}
double average=0;
double sum=0;
for(int i=0;i<count-1;i++){
sum+=arrayofnumber[i];
}
average=sum/(count-1);
cout<<"Result = "<<average;
getch();
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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS