Thread: Lab 2
View Single Post
Old
chickentree
Super Moderator
 
Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
Default 10-14-2016, 01:59 AM

Quote:
Originally Posted by lucyrn99 View Post
Yes, this one is challenging!
I have my character spinning the correct number of times, but I can't get the part where I ask the user 'do you want the object to spin again? question, and if they say 'yes', make the loop happen.

I'm using a string type variable for my 'yes or no' question.
I'm also using the 'if' statement to say 'if yes or no == yes', then repeat the spin process.

It's not working at all, when I answer 'yes'.

I've also tried the 'while' statement to see if 'while "true", make the object spin again' would work, but it did not..

Back to the drawing board, and more reading.. this is not as simple as I thought it would be!
The while block will repeat as long as the statement evaluates to true. Since true will always equal true the while will continue forever.
Depending on how it was written several things could be happening.
You could have declared a variable called yes and another called no. Which would have been set to some value. Your expression is (yes or no == yes) this will first evaluate yes or no. Remember that in this case yes does not mean "yes" instead yes is a label for a variable. The variable can hold a certain type of value like a number, a Boolean (true or false) or a string.
The (yes or no ) will look at the contents of the variables and if Alice considers either variable to be true then the result will be true. At this point Alice will have ((yes or no)==yes -> (true == yes). Finally, if the contents of the variable yes equals true then the final result will be true otherwise it will be false.

Here is what you need to do:

create a string variable called answer
set the value to "yes"

while answer == "yes"
do whatever
Ask if the user wants to continue
// from here the code goes back to the while

// if the answer is anything else then you end up here and continue on

Last note: if the user types anything but "yes" the while will end. This includes Yes YES yeS yes with a space on either end....


Mark Henwood
mhenwood@ieee.org
   
Reply With Quote