Avg age of any no. of ppl while 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;


    while(age!=-1){

        ageTotal = age + ageTotal;

        totalppl = totalppl + 1; //Important


         cout << "Enter next persons age or -1 to exit: " << endl;

         cin >> age;

    }

    cout << "Total People Entered is: " << totalppl << endl;

    cout << "Average age is : " << ageTotal/totalppl << endl;


    return 0;


}


Comments

Popular posts from this blog

Hackerearth Pr1.

Avg age of any no. of ppl for loop

Random Number