PDA

View Full Version : How do I make an if/else equal yes?

HalBen18
03-20-2014, 08:51 PM
I have a program where a girl asks the user how many times they want her to spin. After that, she jumps up, spins that amount and then comes down. Then I ask the user if the want the program to repeat. I need help with if they input "yes" to have it run again. If they say no, she needs to say goodbye. I can't find a yes or no equation. Then I can't figure out how to use a loop to do this so that it will run continually as long as the user keeps entering "yes" at the end. Help please?

MrMoke
03-20-2014, 09:22 PM
The cool thing about Boolean variables is that they can only be one of two possibilities at any given time.
So, if you create a variable called something like "running" and make it "true", you can use it anywhere there is a true/false test.
If "running"
do something
else
do something else

OR
While "running"
do a bunch of stuff over and over
and change "running to false to stop the loop

See if you can modify this code to print "true" four times before printing "false".
Don't just add three more print lines.
Instead, create a numeric "counter" and add test logic to determine when to set "running" to "false". Just a few lines of code will let you print any number of trues.

levimrj
03-28-2014, 02:34 PM
I did not know you could make a true false statement like that!! I just got through with my assignment of the spinning character and I used a 'while' statement. Not sure if the 'while' is preferable over the 'if/else' statement but I figured since I didn't have an 'else' for my character to do, I used the 'while' statement. Some of these assignments seem hard until I really start thinking about what I'm writing in the program and then it makes sense.

MrMoke
04-10-2014, 03:24 PM
It's what programmers do :)

Click and Open the attached Movie