67 058
Assignments Done
99,3%
Successfully Done
In November 2018

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.
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions