
-----------------------------------
MPVoiD
Thu Jan 22, 2015 1:19 pm

Help
-----------------------------------
My CompSci teacher wanted me to "write a function that returns a larger of two numbers". I'm extremely new at Turing and wondering what needs to be done in order for  this to work.

This is what I have right now, but it comes back with errors.

 var num1, num2 :int
   put "Enter two different numbers."
    get num1 
    get num2 

  if num1 > num2 then
    put num1
    
  if num2 > num1 then 
    put num2

-----------------------------------
Zren
Thu Jan 22, 2015 1:27 pm

RE:Help
-----------------------------------
What does the error say?

-----------------------------------
MPVoiD
Thu Jan 22, 2015 7:45 pm

Re: Help
-----------------------------------
It says "Syntax error at 'end of file'. Expected 'end if'.

-----------------------------------
bubb4h0t3p
Thu Jan 22, 2015 7:46 pm

Re: Help
-----------------------------------
you forgot to close your if statements with "end if"


var num1, num2 :int 
put "Enter two different numbers." 
get num1 
get num2 

% just puts a blank line
put ""

% you're if statements weren't closed with an "end if"
if num1 > num2 then 
put num1 
end if % < always add after your if statement

if num2 > num1 then 
put num2
end if % < here too



By the way everything after a "%" sign is a comment and ignored by the compiler

-----------------------------------
MPVoiD
Thu Jan 22, 2015 7:52 pm

Re: Help
-----------------------------------
oh, so I need to type "end if" after each if statment. Thank you very much - it work's now.

-----------------------------------
MPVoiD
Sat Jan 24, 2015 12:39 pm

Re: Help
-----------------------------------
How would I make this program work using a function?

-----------------------------------
Insectoid
Sat Jan 24, 2015 4:06 pm

RE:Help
-----------------------------------
Do you know how to use functions at all?

-----------------------------------
Zren
Sat Jan 24, 2015 4:59 pm

RE:Help
-----------------------------------
The Turing Walkthrough has a pretty good guide on functions if you don't.

[url=http://compsci.ca/v3/viewtopic.php?t=14665]Functions and Procedures
