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

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




PostPosted: Mon Feb 27, 2012 7:08 pm   Post subject: ProcedureHELP!!!

What is it you are trying to achieve?
I am trying to make this procedure but it always errors on me!!!


What is the problem you are having?
var Celsius, Fahrenheit : int
const Celsius_to_Fahrenheit := 9/5 + 32

procedure p_input
put "Enter the temperature in Celsius:"
get Celsius
end p_input

procedure p_process
Fahrenheit := Celsius * Celsius_to_Fahrenheit
put ""
end p_process

procedure p_output
put "Farenheit value is:"
put Fahrenheit
end p_output

p_input
p_process
p_output

after Fahrenheit := Celsius * Celsius_to_Fahrenheit
it errors on Celsius_to_Fahrenheit or ANYTHING I put there :'(



Describe what you have tried to solve this problem
I have tried to change the value and the * sign to + or -


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

Turing:


var Celsius, Fahrenheit : int
const Celsius_to_Fahrenheit := 9/5 + 32

procedure p_input
    put "Enter the temperature in Celsius:"
    get Celsius
end p_input

procedure p_process
    Fahrenheit := Celsius * Celsius_to_Fahrenheit
    put ""
end p_process

procedure p_output
    put "Farenheit value is:"
    put Fahrenheit
end p_output

p_input
p_process
p_output 



Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
crossley7




PostPosted: Mon Feb 27, 2012 7:13 pm   Post subject: RE:ProcedureHELP!!!

well, first of all look at your constant. It is just a value = 9/5+32 = 169/5 rather than a formula which is what you need. Also, your variables are integers but in the majority of cases are supposed to be reals. I think that should be enough to help you find your problems. The procedures themselves are not your issue
MrGuild125




PostPosted: Mon Feb 27, 2012 7:23 pm   Post subject: RE:ProcedureHELP!!!

It was the variables Razz they needed to be reals like u said Very Happy TY TY Smile
MrGuild125




PostPosted: Mon Feb 27, 2012 7:25 pm   Post subject: RE:ProcedureHELP!!!

Would you like to maybe explain why it needs to be a real? if not thats fine I would just like the knowledge so I dont run into this again Smile
smool




PostPosted: Mon Feb 27, 2012 9:00 pm   Post subject: RE:ProcedureHELP!!!

an integer value is just whole numbers, no decimal points, where as a real value has decimal points. So when multiplying the Celcius by (9/5), it gives you a number with decimal points, which is why you need a real value.
crossley7




PostPosted: Mon Feb 27, 2012 9:24 pm   Post subject: RE:ProcedureHELP!!!

In general for turing number types you have ints and reals. The difference between the 2 is as follows.

int - as it says, it is an integer. This means positive or negative values that contain 0 decimal places.
eg. -1,5,20,-86 etc.

real - also self explanatory, a real number. This is any positive or negative number that has no imaginary components (if you aren't in grade 11 yet, then any number that you have used in math class)

eg. 5.5, 3.3333, 8.12345 etc

Keep in mind what types of values you want to have in your programming which type of variable you use. Celsius and Fahrenheit are values that can be non integer and so must be defined as real. Look up the different types for variables that you can use so you can choose the best type for your purposes in your programs.
MrGuild125




PostPosted: Mon Feb 27, 2012 10:55 pm   Post subject: RE:ProcedureHELP!!!

Yea I just hit grade 11 and am in computer programming, thanks for the help Smile I'm 3 chapters ahead so my peers cant help and the teacher is busy helping others move past var/cont type : int Razz and ya I knew ints and reals I was just being an idiot and didnt realize but thanks for pointing that out for me! Very Happy
MrGuild125




PostPosted: Mon Feb 27, 2012 10:58 pm   Post subject: RE:ProcedureHELP!!!

I have 1 last question you may be able to help with. In this program I need to say

if (sum >10 and < 19) then
put "your number is between 10 and 19"
end if

How can I do this with the knowledge of , procedures, variables, const, and all the small stuff between that?
Sponsor
Sponsor
Sponsor
sponsor
crossley7




PostPosted: Mon Feb 27, 2012 11:06 pm   Post subject: RE:ProcedureHELP!!!

basically as you just stated. Just remember both sides of every condition need a value and check if you want <= or >=. No need for constants, procedures, etc.

A single variable that you get (again make sure you have the correct type) and then an if statement checking if it is in a range.
MrGuild125




PostPosted: Mon Feb 27, 2012 11:10 pm   Post subject: RE:ProcedureHELP!!!

But... sum > 10 and < 19 errors on me? so I thought it had to be done a different way?
crossley7




PostPosted: Mon Feb 27, 2012 11:22 pm   Post subject: RE:ProcedureHELP!!!

like I said both sides of the condition need a value.

condition 1 there is sum > 10
condition 2 there is < 19

you just have to learn to think as the computer thinks. the and is the start of another condition. or does the same thing.
MrGuild125




PostPosted: Mon Feb 27, 2012 11:28 pm   Post subject: RE:ProcedureHELP!!!

Can this be done all in one if statement? because It needs to be all in 1 if statement :/

code:

var value, sum, x : int
var category : string

procedure p_input
    put "Please enter a value."
    get value
end p_input

procedure p_process
    sum := value * value
   
    if (sum <= 10) then
        category := " a number less than 10"
    end if
   
    if (sum) then%I want it all to occur in this one if statement
    end if
 
end p_process

procedure p_output
    put ""
    put value, " squared is: ", sum
    put "The category is:", category
end p_output

p_input
p_process
p_output
   
crossley7




PostPosted: Mon Feb 27, 2012 11:45 pm   Post subject: RE:ProcedureHELP!!!

procedure p_process
sum := value * value

if (sum <= 10) then
category := " a number less than 10"
end if

if (sum) then%I want it all to occur in this one if statement
end if

end p_process

becomes

if value*value <= 10 then
category := " a number less than 10"
elsif next condition
elsif ...
else (whatever your final possible result is)

If you have more questions, look in the Turing Documentation first before posting. Also, look at things you could change into 1 line such as assigning a variable and then looking at it only once and that is in an if.
MrGuild125




PostPosted: Mon Feb 27, 2012 11:58 pm   Post subject: RE:ProcedureHELP!!!

Thanks I got it Smile
TW iz Rippin




PostPosted: Tue Feb 28, 2012 10:54 am   Post subject: RE:ProcedureHELP!!!

your variables need to be real
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  [ 15 Posts ]
Jump to:   


Style:  
Search: