Basic age asker program in C++
I used to do a little programming in c++, but I haven't for a while, and
just recently started again. I decided to write a basic program to see
where I'm at, as far as knowledge of the language. The program i wrote
asks for the user's age, take's the input, and then has 3 options to
choose from based on the user's input. Here is my code
#include <iostream>
using namespace std;
int main()
{
int age;
cout << "Please enter your age\n";
cin >> age;
bool error = false;
while (error = false)
{
if (age > 105)
{
cout << "You're Too Old\n";
continue;
}
else if (age < 1)
{
cout << "You haven't been born yet!\n";
continue;
}
else
{
error = true;
continue;
}
}
cout << "Your age is: " << age << "\n";
return 0;
}
My problem comes when I do enter an age that's outside of the range of
1-105. For some reason, it skips the entire if statement and just runs the
code at the bottom. If someone could help me with this, I would appreciate
it.
No comments:
Post a Comment