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

Started by
1 comment, last by phil05 20 years ago
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);
		}
}
 
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]
FTA, my 2D futuristic action MMORPG
also, if that doesnt work, just use getche()
FTA, my 2D futuristic action MMORPG

This topic is closed to new replies.

Advertisement