Posted: Fri Jun 01, 2007 8:23 am Post subject: case construct...the easy way
Selective structures: Case Construct
Case construct is an efficient way to creating menus. It does not however allow the coder to do anything that an if statement can't do; it's just better at handling certain tasks. Try this
Turing:
var command: int
loop
put"Choose from 1 to 4:"..
get command
case command of
label1:
put"Hi there"
label2:
put"How are you? "
label3:
put"Really?"
label4:
put"Bye Bye"
label:
put"That is not an option "
exit
endcase
endloop
Notice that the final label functions similarly to an else.
--------------------------------------------------------------------------------------
to practice try these:
1) Write a traffic light program. The traffic light itself should be a graphic. It will flash a light colour at random.Ask the user what colour the light is and output the correct instructions for the chosen light colour.
2) Write a program that will convert the user's weight to the equivalent weight on any other planet.The user should be able to choose which planet.
3) Modify 2 such that a picture of the planet is displayed.
Sponsor Sponsor
Cervantes
Posted: Fri Jun 01, 2007 7:11 pm Post subject: RE:case construct...the easy way
Again, I fixed up the post. Same comments as in the other one apply.
Tallguy
Posted: Sat Jun 02, 2007 3:35 pm Post subject: RE:case construct...the easy way