fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main () {
  8. int age;
  9. int ageTotal = 0;
  10. int geometric_mean=1;
  11.  
  12. int numberOfpeopleEntered = 0;
  13.  
  14. cout << "Enter first persons age or -1 to quit "<<endl;
  15. cin>>age;
  16.  
  17. while (age != -1){
  18. ageTotal = ageTotal + age;
  19. numberOfpeopleEntered++;
  20.  
  21. cout<<"Enter next persons age or -1 to quit "<<endl;
  22. cin>>age;
  23. }
  24. cout<<"Number of people entered: "<<numberOfpeopleEntered<<endl;
  25. cout<<"Average age:"<<ageTotal/ numberOfpeopleEntered<<endl;
  26. cout<<"Geometric mean: "<<pow(geometric_mean,.5)<<endl;
  27. return 0;
  28. }
Success #stdin #stdout 0s 2900KB
stdin
2
7
4
8
-1
stdout
Enter first persons age or -1 to quit 
Enter next persons age or -1 to quit 
Enter next persons age or -1 to quit 
Enter next persons age or -1 to quit 
Enter next persons age or -1 to quit 
Number of people entered: 4
Average age:5
Geometric mean: 1