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

Username:   Password: 
 RegisterRegister   
 Menus: How to switch back to a processes undeclared??
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
marsbarz




PostPosted: Mon Apr 04, 2005 9:55 am   Post subject: Menus: How to switch back to a processes undeclared??

I'm writing this program for my compsci class, and yes, I'm using processes. I know I read the thread on why processes should be avoided but I think in this case it's not really necessary to put everything into a loop because in the end it'll get me the same amount of marks. Razz

BUT here is where I might be wrong!

I am actually very new to turing and programming in general and I ran into this little problem while I was writing my program.

I used a process to create a menu screen for the program which would run at the start.

But now that menu has a selection process which has to be declared before the menu so that the menu can utilize the selection (can't run an undeclared process). But now, there is an option on that menu selection process that is supposed to return the user back to the menu if their selection is invalid.

So I'm wondering exactly what I should be doing here? Should I just put everything into a loop somehow (still haven't figured out how I'm going to do that) or is there a method to manipulate the code so I can jump to a process that is otherwise undeclared?

Here is the code specific to my problem, pre-declared variables and stuff not included:
code:
proc menudecision
    getch (menuselect)
    if menuselect = "a" or menuselect = "A" then
        selectiona
    elsif menuselect = "b" or menuselect = "B" then
        selectionb
    elsif menuselect = "c" or menuselect = "C" then
        selectionc
    elsif menuselect = "d" or menuselect = "D" then
        selectiond
    elsif menuselect = "e" or menuselect = "E" then
        selectione
    elsif menuselect = "f" or menuselect = "F" then
        selectionf
    elsif menuselect = "g" or menuselect = "G" then
        selectiong
    elsif menuselect = "h" or menuselect = "H" then
        selectionh
    elsif menuselect = "i" or menuselect = "I" then
        selectioni
    elsif menuselect = "j" or menuselect = "J" then
        selectionj
    else
        cls
        Draw.Text ("The selection you have made is incorrect", 200, 200, system10, white)
        Draw.Text ("Select either A, B, C, D, E, F, G, H, I, or J", 200, 180, system10, white)
        Draw.Text ("Press any key to return to menu...", 200, 160, system10, white)
        getch (anykey)
        menudraw /* <-- how to get to menudraw if it's not declared yet?*/
    end if
end menudecision

proc menudraw
    colourback (blue)
    cls
    Draw.Text ("Select a menu item", 5, 5, arial12bold, white)
    Draw.Text ("A. Perimeter calculator for circles", 200, 350, arial10, white)
    Draw.Text ("B. Perimeter calculator for traingles", 200, 330, arial10, white)
    Draw.Text ("C. Perimeter calculator for rectangles", 200, 310, arial10, white)
    Draw.Text ("D. Area calculator for circles", 200, 290, arial10, white)
    Draw.Text ("E. Area calculator for triangles", 200, 270, arial10, white)
    Draw.Text ("F. Area calculator for rectangles", 200, 250, arial10, white)
    Draw.Text ("G. Surface area calculator for cylinders", 200, 230, arial10, white)
    Draw.Text ("H. Volume calculator for a sphere", 200, 210, arial10, white)
    Draw.Text ("I. Volume calculator for a cylinder", 206, 190, arial10, white)
    Draw.Text ("J. Quit", 206, 170, arial10, white)
    menudecision
end menudraw


Thank you in advance for any help!
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Mon Apr 04, 2005 10:46 am   Post subject: (No subject)

First off, you're using Procedures not Processes in your code...
And the loop idea sounds good. Try this as your basic method for coding:
- think about everything that your code has to do.
- anything that can be put into a box, do so (in this case your boxes will be procedures - *very* useful thinggies - stick with them)
- keep in mind that in OOT all procs etc used have to be declared before they're used...so basically programme so that the most global procs are made first, followed by more local ones.
- in the end, use one final, main, super, simple proc to call all the other ones in the order needed...
Cervantes




PostPosted: Mon Apr 04, 2005 12:55 pm   Post subject: (No subject)

[quote="Delos"]
- keep in mind that in OOT all procs etc used have to be declared before they're used...so basically programme so that the most global procs are made first, followed by more local ones.
quote]
Declared, yes. But you don't have to have written the entire procedure before you call it. Rather, you can forward the procedure. Best learned by example:

Turing:

forward procedure foo

procedure bar
    put "bar"
    foo
end bar

body procedure foo
    put "foo"
    bar
end foo

foo
marsbarz




PostPosted: Wed Apr 06, 2005 9:52 am   Post subject: (No subject)

Surprised
Thank you guys so much for the help, now I see what I should've done.

Haha, I always thought proc meant process, re-reading my own post knowing otherwise now makes my own post very annoying to read, lol.

Thanks again =)
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: