RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 969 | Replies: 1
Reply
Join Date: Jul 2005
Posts: 26
Reputation: Rearden is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Rearden's Avatar
Rearden Rearden is offline Offline
Light Poster

help with validating function

  #1  
Jul 21st, 2005
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;
		}
	}

}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2005
Posts: 26
Reputation: Rearden is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
Rearden's Avatar
Rearden Rearden is offline Offline
Light Poster

Re: help with validating function

  #2  
Jul 22nd, 2005
Whoops. I accidentally was setting the age again from within the function for setting the weight. Fixed now. Thanks anyway.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 11:14 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC