Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 case construct...the easy way
Index -> Programming, Turing -> Turing Tutorials
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Tallguy




PostPosted: 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

label 1:

put "Hi there"

label 2:

put "How are you? "

label 3:

put "Really?"

label 4:

put "Bye Bye"

label:

put "That is not an option "

exit

end case

end loop


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
Sponsor
sponsor
Cervantes




PostPosted: 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




PostPosted: Sat Jun 02, 2007 3:35 pm   Post subject: RE:case construct...the easy way

thanks cervantes
Display posts from previous:   
   Index -> Programming, Turing -> Turing Tutorials
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: