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

Username:   Password: 
 RegisterRegister   
 Procedure Greet Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
storm2713687




PostPosted: Mon Feb 25, 2013 2:55 pm   Post subject: Procedure Greet Help

What is it you are trying to achieve?
I'm trying to fix my code, but I'm not sure what's wrong with it.


What is the problem you are having?
I can't get the script to run because r is not declared.


Describe what you have tried to solve this problem
I've actually tried to fix it already, but I just can't get it to run, and I'm just trying to make my script shorter without repeating things over and over again.


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

Turing:


put "--------------------------------------------------------------------------------" %80 Dashes
put "Welcome to Edward Yang's circumference and area of a circle calculator."         %Made at 10:22 pm 2/21/13
put "     "
put "Please enter 1 for the first prompt, and 1 for the second if you would like to  have only circumference calculated."
put "                           "
put "Please enter 1 for the first prompt, and 2 for the second if you would like to  have only the area of a circle calculated."
put "                           "
put "Please enter 2 for the first prompt, and 1 for the second if you would like to have both of the above calculated."
var p1, p2, p3 : int           %Prompt 1: 2*pi*r
put "  "                       %Prompt 2: Pi*R**2
put "Prompt #1: " ..           %Prompt 3: Both above
get p1
put "Prompt #2: " ..
get p2
put "--------------------------------------------------------------------------------"
procedure greet
    var r : real
    put "If you have the length of the diameter, divide  it by two to get the radius."
    put "--------------------------------------------------------------------------------"
    put "Enter the length of the radius here: " ..
    get r
    put "--------------------------------------------------------------------------------"
end greet
put "Note: Do not state the units you are using. Just input the numbers. If you have the length of the diameter, divide it by 2 to get the radius."
put "--------------------------------------------------------------------------------"  % 80 dashes.
const pi : real := 3.14
%Prompt #1
if p1 = p2 then
    greet
    put "C=2*Pi*R"
    put "C=2*", pi, "*", r
    put "C=", 2 * pi * r
    put "The circumference of the circle is ", 2 * pi * r, "."
    put "--------------------------------------------------------------------------------"
%Prompt #2
elsif p1 < p2 then
    greet
    put "A=Pi*R**2"
    put "A=", pi, "*", r, "**2"
    put "A=", pi, "*", r ** 2
    put "A=", pi * (r ** 2)
    put "The area of the circle is ", pi * (r ** 2)
%Prompt #3
else
    greet
    put "C=2*Pi*R"
    put "C=2*", pi, "*", r
    put "C=", 2 * pi * r
    put "The circumference of the circle is ", 2 * pi * r, "."
    put "--------------------------------------------------------------------------------"
    put "A=Pi*R**2"
    put "A=", pi, "*", r, "**2"
    put "A=", pi, "*", r ** 2
    put "A=", pi * (r ** 2)
    put "The area of the circle is ", pi * (r ** 2)
    put "--------------------------------------------------------------------------------"
end if




Please specify what version of Turing you are using
I'm using version 4.1.1 for windows.

P.S. I read that this version of Turing can't generate a stand-alone program. Which version should I use then? I'm using a 64 bit windows 8 computer. Thanks for helping. Smile
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Mon Feb 25, 2013 3:07 pm   Post subject: RE:Procedure Greet Help

You declared r inside greet. That means you can only use it from inside greet. If you want to use it anywhere else, you need to declare it globally (ie not inside any procedure).
storm2713687




PostPosted: Tue Feb 26, 2013 8:38 am   Post subject: Re: RE:Procedure Greet Help

Insectoid @ Mon Feb 25, 2013 3:07 pm wrote:
You declared r inside greet. That means you can only use it from inside greet. If you want to use it anywhere else, you need to declare it globally (ie not inside any procedure).


Should I declare r from outside the greet procedure? Also, thanks for helping and posting here in my thread. Very Happy

Edit: OHH NVM, I FOUND OUT WHY IT DIDN'T WORK. Thanks for all the help though, guys! Smile
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  [ 3 Posts ]
Jump to:   


Style:  
Search: