Yes or No question in VS 2010 C++?

I'm taking a programming class and I have to write a program that asks for a username, password, and email. I'll get up to 20 bonus points if I go the extra mile and do something special, so I'm making it so it asks you to verify the information with "yes" or "no."

Thing is, I forgot how to do this. I know it goes something like this:

if yesorno = yes
"Very good. The email has been sent.

else

"We are sorry. We will do our best to fix this."

Etc.

Someone help?
Assuming that your variable is named "yesorno" the syntax would be like this:

if(yesorno=1) //ask the user to input 1 for yes and 2 (or any other number, since we are using else) for no
printf("Very good. The email has been sent.");

else
printf("We are sorry. We will do our best to fix this.");
@Askwer

I would hope that printf() would lose marks when writing a C++ program. I'd expect cout to be used here.

And why not use 'y' for yes and 'n' for no, rather than 1 or 2?

@Chowder138

Once you have the response, in whatever format, the logic in your pseudocode makes sense. But, assuming you're using the console, you'll need to handle invalid responses, too (there's no easy way to restrict console input.)

Is the following information right?
username: andywestken
password: ********
e-mail: andywestken@cplusplus.com
Please enter 'y' for yes, 'n' for no:
>apples

That does not compute!

Please enter 'y' for yes, 'n' for no:
>pears

That does not compute!

Please enter 'y' for yes, 'n' for no:
>stairs

Danger! Danger! Stupid person attempting to control
this computer. Initiating program shutdown sequence.
3
2
1
We're back in the room!
Shutdown complete


Andy

PS Most systems never actually display the password, just *s. And they get you to type it in twice. Not sure easy that would be to do, though.

Last edited on
Topic archived. No new replies allowed.