Answer to Question #24808 in C++ for Rashed Alkhuzai

Question #24808
Create a C++ program that reads N integers and prints their average. Your program should ask first for a value N. Using a while loop, get the N integers and compute their average. At the end, print the average. Your program should print an appropriate message if the user enters 0 as the value for N.
1
Expert's answer
2013-02-20T11:46:54-0500
#include <iostream>
using namespace std;
int main(){
cout<<"Enter N\n";
int N;
cin>>N;
if (N==0) cout<<"You entered the wrong number N=0\n";
else {
double av = 0;
int NN = N;
while (NN >0)
{
NN--;
double temp;
cin>>temp;
av+=temp;
}
cout<< "Average: "<<av/N<<endl;

}

system("pause");
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