Program that determines number of inputted riders and closes when -1 is inputted?

As the title says, I seem to be having a logical error but can not find the sources.

#include <iostream>
using namespace std;



int main()
{
int student = 0;
int adult = 0;
int senior = 0;
int count = 0;
int x = 1;
int i;

cout << "How old was everyone who got on the train? At the end of the list enter -1 to end the list. " << endl;


{
for (x = 1; x > -1; x++)
{
cin >> x;
}

if (x <= 17)
{
student++;
count++;
}
else if ((x > 17) && (x < 65))
{
adult++;
count++;
}
else if (x > 65)
{
senior++;
count++;
}
}
cout << "The total number of students, adults, and seniors who rode the train today is: " << student << " students, " << adult << " adults, and " << senior << " seniors. " << endl;
return 0;

}
What did you intend this piece of code to accomplish? You have a for loop with an increasing x that can only stop when the user inputs a negative number. -5 would also stop it. So would -6743.
1
2
3
4
for (x = 1; x > -1; x++)
{
    cin >> x;
}
Last edited on
Topic archived. No new replies allowed.