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

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




PostPosted: Thu Jan 22, 2015 1:19 pm   Post subject: 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
Sponsor
Sponsor
Sponsor
sponsor
Zren




PostPosted: Thu Jan 22, 2015 1:27 pm   Post subject: RE:Help

What does the error say?
MPVoiD




PostPosted: Thu Jan 22, 2015 7:45 pm   Post subject: Re: Help

It says "Syntax error at 'end of file'. Expected 'end if'.
bubb4h0t3p




PostPosted: Thu Jan 22, 2015 7:46 pm   Post subject: Re: Help

you forgot to close your if statements with "end if"

Turing:

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




PostPosted: Thu Jan 22, 2015 7:52 pm   Post subject: Re: Help

oh, so I need to type "end if" after each if statment. Thank you very much - it work's now.
MPVoiD




PostPosted: Sat Jan 24, 2015 12:39 pm   Post subject: Re: Help

How would I make this program work using a function?
Insectoid




PostPosted: Sat Jan 24, 2015 4:06 pm   Post subject: RE:Help

Do you know how to use functions at all?
Zren




PostPosted: Sat Jan 24, 2015 4:59 pm   Post subject: RE:Help

The Turing Walkthrough has a pretty good guide on functions if you don't.

Functions and Procedures
Sponsor
Sponsor
Sponsor
sponsor
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  [ 8 Posts ]
Jump to:   


Style:  
Search: