Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Somebody Tell me What im doing Wrong
Author Message
Krocker

Posted: Mon Nov 01, 2010 5:31 pm   Post subject: Somebody Tell me What im doing Wrong

Hiya, im new to turing. I wanted to do something simple to start. here is my coding:

% Calculates the total Average of 4 classes
loop
var average:real
var average1:real
var average2:real
var average3:real
var average4:real
colour(10)
get average1
colour (11)
get average2
colour (9)
get average3
colour (6)
get average4
colour (black)
% Calculates the total average
delay(2000)
average:= (average1+average2+average3+average4)/4
% Shows the total average
put average
if average > 50 then
put "passing"
else if average > 50 then
put "failing"
else
put "You are in the middle"
end if

When i go to play, i keep getting a compilation error message. im not sure wats wrong, i have tried different things. can someone plz help me and tell me wats wrong. thjx

TheGuardian001

Posted: Mon Nov 01, 2010 5:55 pm   Post subject: Re: Somebody Tell me What im doing Wrong

If you look at what the error says, you'll see that you're missing an "end if"
If you look at it again, you'll see you're also missing an "End loop"

And finally,
 code: if average > 50 then put "passing" else if average > 50 then put "failing" else put "You are in the middle" end if

Both of those conditions are > 50. The second one should be <50.
Krocker

Posted: Mon Nov 01, 2010 6:03 pm   Post subject: Re: Somebody Tell me What im doing Wrong

I do have an "end if", i added an end loop and its says that it should be end if. but i already have one! im so confused!

TheGuardian001 @ Mon Nov 01, 2010 5:55 pm wrote:
If you look at what the error says, you'll see that you're missing an "end if"
If you look at it again, you'll see you're also missing an "End loop"

And finally,
 code: if average > 50 then put "passing" else if average > 50 then put "failing" else put "You are in the middle" end if

Both of those conditions are > 50. The second one should be <50.
SNIPERDUDE

Posted: Mon Nov 01, 2010 6:05 pm   Post subject: RE:Somebody Tell me What im doing Wrong

And just a side note:
This post would make more sense in the Turing Help section as opposed to the Turing Tutorials section.

Also, posted code is easier to read (as it keeps indentation and colour the same) when you use syntax tags
 code: [syntax="turing"]paste code here[/syntax]

Just for future reference.
TheGuardian001

Posted: Mon Nov 01, 2010 6:16 pm   Post subject: Re: Somebody Tell me What im doing Wrong

Krocker @ Mon Nov 01, 2010 6:03 pm wrote:
I do have an "end if", i added an end loop and its says that it should be end if. but i already have one! im so confused!

You started another "if" with your else if. The correct way to use an else if is to use elsif.
DemonWasp

Posted: Mon Nov 01, 2010 6:25 pm   Post subject: RE:Somebody Tell me What im doing Wrong

Block constructs (meaning IF, LOOP, FOR, etc) must be properly nested. This means that the following examples are valid:

 code: loop     if     end if end loop

 code: loop     if         if         end if     end if end loop

But these examples are not valid:
 code: loop     if     end loop (missing an end-if here!) end if (can't be outside the loop!)

Most importantly, Turing uses "elsif", not "else if". This code:
 code: if average > 50 then put "passing" else if average > 50 then put "failing" else put "You are in the middle" end if

looks like this to Turing (indentation added to show blocks):
 code: if average > 50 then     put "passing" else     if average > 50 then         put "failing"     else         put "You are in the middle"     end if

what you want is:
 code: if average > 50 then     put "passing" elsif average > 50 then     put "failing" else     put "You are in the middle" end if
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 6 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: