hey andy, thanks for the help. its coming together bit by bit. One thing im stuck on is why my age groups are not functioning correctly.
please enter age of attendees (-1 to quit): 34
please enter age of attendees (-1 to quit): 16
please enter age of attendees (-1 to quit): 68
please enter age of attendees (-1 to quit): 53
please enter age of attendees (-1 to quit): 39
please enter age of attendees (-1 to quit): 23
please enter age of attendees (-1 to quit): 21
please enter age of attendees (-1 to quit): -1
The total number of attendees is 7
The average age of the attendees is :36.29
Lowest age was: 16
highest age was: 68
ages 0-18: 1
ages 19-30: 2
ages 31-40: 1
ages 41-60:1
ags 60 and up: 1
Process returned 0 (0x0) execution time : 20.551 s
Press any key to continue.
the age group form 31-40 should be 2 instead of 1 and im not to sure what I did wrong. It doesent count either 34 or 39?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int age, age1 = 0, age2 = 0, age3=0, age4=0, age5=0, sum = 0, counter = 0, low, high;
double average = 0;
cout << "please enter age of attendees (-1 to quit): ";
cin>>age;
while (age != -1)
{
if (counter ==0)
{
high = age;
low = age;
}
else
{
if (age < low && age != -1)
low = age;
if
(age > high && age != -1)
high = age;
}
counter++;
sum+= age;
cout << "please enter age of attendees (-1 to quit): ";
cin>>age;
if (age>=0 && age<=18)
{
age1++;
}
if (age>=19 && age<=30)
{
age2++;
}
if (age>=31 && age<=40)
{
age3++;
}
if (age>=41 && age<=60)
{
age4++;
}
if (age>=61)
{
age5++;
}
}
cout<<fixed<<showpoint<<setprecision(2)<<endl;
cout << "The total number of attendees is " << counter << endl;
average=static_cast<double>(sum)/counter;
cout << "The average age of the attendees is :" << average << endl;
cout << "Lowest age was: " << low << endl;
cout << "highest age was: " << high << endl;
cout << "ages 0-18: " << age1 <<endl;
cout << "ages 19-30: " << age2 <<endl;
cout << "ages 31-40: " << age3 <<endl;
cout << "ages 41-60:" << age4 <<endl;
cout << "ags 60 and up: " << age5 <<endl;
return 0;
}
|