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

Username:   Password: 
 RegisterRegister   
 Turing Script Help (urgent)
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MikeAlexnder




PostPosted: Sat Dec 20, 2008 2:49 pm   Post subject: Turing Script Help (urgent)

Turing:

var option2 : int
        get option2
        case option2 of
            label 1 :
                var balance, interestRate, interest : real

                function roundCent (amount : real) : real
                    % Round amount to nearest cent
                    result round (amount * 100) / 100
                end roundCent

                procedure banker (var balance, interest : real, interestRate : real)
                    interest := roundCent (balance * interestRate / 100)
                    balance := balance + interest
                end banker

                put "Enter balance: " ..
                get balance
                put "Enter current interest rate: " ..
                get interestRate
                banker (balance, interest, interestRate)
                put "New balance = ", balance
                put "Interest = ", interest
               label 2put "Interest = "
               end case




Can someone help me fix this code
I can't run it because of the function and procedure and I need it

Mod Edit: No need for excessive caps. Also remember to use syntax tags
code:
[syntax="Turing"]Code Here[/syntax]
Sponsor
Sponsor
Sponsor
sponsor
TheGuardian001




PostPosted: Sat Dec 20, 2008 5:03 pm   Post subject: Re: Turing Script Help (urgent)

1) Use code/syntax tags
code:

[code]
this will appear in a code box
[/code]
[syntax="turing"]
this will appear in a Turing syntax box
[/syntax]


anyway, your problem is that you can't declare functions/procedures inside of a case/if structure. Move the procedure and function out of the case and it should be fine, provided the code works properly.
MikeAlexnder




PostPosted: Sat Dec 20, 2008 7:55 pm   Post subject: RE:Turing Script Help (urgent)

How do you do that? Can you send the edited script? (The program works if I remove case but I need it so I can't get rid of it)
TheGuardian001




PostPosted: Sun Dec 21, 2008 1:07 pm   Post subject: Re: Turing Script Help (urgent)

What I mean by that is to literally take the section of code that is inside a function/ procedure and move it outside of the case statement.

what you have now:

Turing:

case blank of
%we are now INSIDE of a case statement
    label 1:
        var variables : real
        %This is being declared INSIDE of that case statement you started up above. this is not allowed.
        function myFunction(params : real) :real
            %contents of Function 1
        end myFunction
        %also INSIDE
        procedure myProc(params:real)
            %contents
        end myProc
        %rest of code.....


when I say to take them out of the case statement, I mean that it should be

Turing:

%This function is now OUTSIDE of the case statement.
function myFunction(params : real) :real
    %contents of Function 1
end myFunction
%also now Outside
procedure myProc(params:real)
    %contents
end myProc

%Other stuff here..
%Now, we can start our case:

case blank of
    label 1:
%etc etc etc....
MikeAlexnder




PostPosted: Sun Dec 21, 2008 1:35 pm   Post subject: RE:Turing Script Help (urgent)

If I do that then how would I be able to create a menu for my program.
Tony




PostPosted: Sun Dec 21, 2008 2:24 pm   Post subject: RE:Turing Script Help (urgent)

Easily. Because the menu and the logic (functions and such) are separate.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
MikeAlexnder




PostPosted: Tue Dec 23, 2008 1:16 pm   Post subject: RE:Turing Script Help (urgent)

Need more help!!!
MikeAlexnder




PostPosted: Tue Dec 23, 2008 1:16 pm   Post subject: RE:Turing Script Help (urgent)

Can't I combine them?
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Dec 23, 2008 1:42 pm   Post subject: RE:Turing Script Help (urgent)

There is no need to.

As TheGuardian001 said above, simply move all of your functions and procedures to the top of your program. The code is not run until it's called, and it will still be available from your case block.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
MikeAlexnder




PostPosted: Tue Dec 23, 2008 7:04 pm   Post subject: RE:Turing Script Help (urgent)

oh ok
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  [ 10 Posts ]
Jump to:   


Style:  
Search: