Monday 7 April 2014

Average of n inputs in c

Posted by Саша 07:36, under | No comments


Average of n inputs in c++? Average of n inputs in c++?

user prompted to input numbers greater than or equal to 0
to terminate program they input -1
I want to average the inputs but I dont want to do it by having the user input HOW MANY numbers they will input
How can I do this??
thanks all


Other Answers:




C++ program for average of n inputs is,

#include<iostream.h>
#include<conio.h>
void main()
{
float Number,Total=0,Average=0;
int Inputs=0;
clrscr();
cout<<"Input numbers greater than or equal to 0:n";
cin>>Number;
for(Inputs=0;Number!=-1;Inputs++)
{
Total+=Number;
cin>>Number;
}
Average=Total/Inputs;
cout<<"Total: "<<Total<<endl;
cout<<"Inputs: "<<Inputs<<endl;
cout<<"Average: "<<Average;
getch();
}









0 коммент.:

Post a Comment