Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

phil05

Getting Input (y/n) instead of (1/0)

This topic is 5349 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I realized it''s a bit trickier. Can you give me a code example so the user can type in "y" or "n"?

char TEMP_PASSWORD[7];
char PASSWORD[] = "natale";
int choice;	

std::cout << "Enter Your Password: ";
std::cin >> TEMP_PASSWORD;

if (strcmp(PASSWORD, TEMP_PASSWORD)) 
{
	std::cout << "\nYou have entered an invalid password. Please contact Phillip Vaira ";
	std::cout << "at \nphil@webula.net if the problem persists." << std::endl;

	std::cout << "\nTry again? (1/0): ";
	std::cin >> choice;
		if (choice == 1)
	        {
			main();
		}
		if (choice == 0)
		{
			exit(1);
		}
}
 

Share this post


Link to post
Share on other sites
Advertisement
why dont you just do

char temp

std::cin >> temp;

if(temp == 'y')
choice = 1;
else choice = 0;

if (choice == 1)
{
main();
}
if (choice == 0)
{
exit(1);
}

[edited by - graveyard filla on March 27, 2004 4:25:59 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!