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
put "Enter Your Averages"
colour(10)
get average1
colour (11)
get average2
colour (9)
get average3
colour (6)
get average4
colour (black)
% Calculates the total average
put "Your total average is"
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
Sponsor Sponsor
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