So my program doesnt seem to be keeping track of the numbers that are inputed for the ages. It takes the last number inputed (which is the input to terminate the loop) and makes that my age variable. How can I make the age variable not be what is inputed last?
CODE
// This program keeps track of how many people in 5 different
// age categories attend a particular movie
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int age; // age the user types in
int count;
int sumSoFar; // sum of all ages
int youngest; // youngest age
int oldest; // oldest age
int group1;
int group2;
int group3;
int group4;
int group5;
char n;
sumSoFar = 0;
count = 0;
cout << "Enter age of attendee (-1 to quit): ";
cin >> age;
while (age != -7){
sumSoFar = sumSoFar + age;
if (age < youngest){
youngest = age;
}
if (age > oldest){
oldest = age;
}
cout << "enter age of attendee (-1 to quit): ";
cin >> age;
count++;
}
if (count == 0){
cout << "There is no average, because you did not "
<< "enter any numbers!";
} else {
cout << "The average age was "
<< sumSoFar/count << endl;
}
if (youngest == -1){
cout << "There is no youngest because you "
<< "did not enter any numbers!";
} else{
cout << "The youngest person in attendance was "
<< youngest << endl;
}
if (oldest == -1){
cout << "There is no oldest because you "
<< "did not enter any numbers!";
} else{
cout << "The oldest person in attendance was "
<< oldest << endl;
}
count == 0;
if (age < 0);
cout << "no age entered" << endl;
if (age <= 18)
group1 = (age <= 18);
cout << "age 0 to 18: " << age << endl;
if (age <= 30)
group2 = (age <= 30);
cout << "age 19 to 30: " << age << endl;
if (age <= 40)
group3 = (age <= 40);
cout << "age 31 to 40: " << group3 << endl;
if (age <= 50)
group4 = (age <= 60);
cout << "age 41 to 60: " << group4 << endl;
if (age > 60)
group5 = (age > 60);
cout << "over 60: " << group5 << endl;
system("pause");
}