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

Username:   Password: 
 RegisterRegister   
 Case Statement?? Help!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
1212




PostPosted: Wed Jun 02, 2010 9:48 pm   Post subject: Case Statement?? Help!

What is it you are trying to achieve?
Hi, I have to create a program that has a main menu that includes the titles of three topics. The titles of each topic on the main menu must connect to a submenu. The submenu must connect to three programs. In total, there must be one main menu, three submenus, and nine subprograms.


What is the problem you are having?
I used the case construct method to distinguish between each topic but it is not working. Is there a limit to the amount of subprograms you can put under each case statement?
in the program i put,
var command:int
put"Press 1 for A"
put"Press 2 for B"
put "Press 3 for C"
get command
case command of
label 1:
(put all the subprograms)
label 2:
(put subprograms.)
All the programs under Label 1 worked but the programs under label 2 dont:(
Please help!

Describe what you have tried to solve this problem
I tried using if statements instead of case construct. but it still didnt work


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


<Add your code here>



Please specify what version of Turing you are using
<Answer Here>
Sad Sad
Sponsor
Sponsor
Sponsor
sponsor
rdrake




PostPosted: Wed Jun 02, 2010 10:18 pm   Post subject: RE:Case Statement?? Help!

Please only post the same topic once. Four is a bit much.
Kharybdis




PostPosted: Fri Jun 04, 2010 7:00 am   Post subject: RE:Case Statement?? Help!

There's a limit.. but it's pretty big.
musicman




PostPosted: Fri Jun 04, 2010 9:30 am   Post subject: Re: Case Statement?? Help!

heres an updated version of your code. i changed some stuff and added some.



Turing:

%EDITED BY THE MUSICMAN

%set up as a procedure simply so that you have a fail-safe 'OTHER' option
procedure mainmenu
    var command : int
    var input : string
    put "Press 1 for A"
    put "Press 2 for B"
    put "Press 3 for C"
    %I added this check syntax. not needed but i thought you would find it helpful.
    %it checks whether or not the input is an integer.
    %You can remove this if you want.
    loop
        get input
        exit when strintok (input)
        cls
        put "Not a number. Try again."
    end loop
    command := strint (input)
    case command of
        label 1 :
            %Replace this put command with your first program
            put "1"
        label 2 :
            %Replace this put command with your second program
            put "2"
        label 3 :
            %Replace this put command with your third program
            put "3"
        label :
            %Error-proofing...always helpful :)
            put "Invalid Input. Try again"
            mainmenu
    end case
end mainmenu
mainmenu


try making all of your subprograms procedures and then just declaring the procedure after each label.
hope this helps.


if you have any more questions feel free to ask.
from, THE MUSICMAN
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: