I have this function in a Dog Class and for some reason, the age nearly always ends up being 77. I can't seem to tell what the problem is. Any ideas?
void Dog::setage()
{
while (1)
{
int age;
std::cout << "Please Enter " << itsname << "'s age: ";
if(!(std::cin >> age))
{
std::string badchars;
std::cin.clear();
std::cin >> badchars;
std::cout << "\"" << badchars << "\"" << " is not a number. Please try again.\n";
}
else if (age < 0 || age > 20)
{
std::cout << "\"" << age << "\"" << " is a strange age for a dog.";
std::cout << "Please try again.\n";
}
else
{
itsage = age;
break;
}
}
}