Avg age of any no. of ppl for loop
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
int age, totalppl = 0, ageTotal = 0;
cout << "Enter First persons age or -1 to exit " << endl;
cin >> age;
for(totalppl; age!=-1; totalppl++)
{
ageTotal = age + ageTotal;
cout << "Enter next persons age or -1 to exit: " << endl;
cin >> age;
}
cout << "\n\n Total no. of people are : " << totalppl << endl;
cout << "\n Avereage age of all the people is: \n\n " << ageTotal/totalppl;
return 0;
}
Comments
Post a Comment