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

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




PostPosted: Thu Oct 09, 2003 5:57 pm   Post subject: Code Revising

Hi, i need my turing code checked over.. turing 4.0.4c keeps on telling me Crying or Very sad to insert END LOOP & END IF even though it is already in it Wink Rolling Eyes :

% ----------------------------------
%
% Report Card
% Written By: Shilin Patel
% Date: 10/08/03
%
% Input: Subjects, Marks
% Output: Average, Marks, Name
% Process: Display Subjects, Get Average Of Marks
%
% ----------------------------------

colorback (black)
color
(brightgreen)

% Declare All Variables
var mark1, mark2, mark3, mark4, total : real
var sub1, sub2, sub3, sub4, name, ans : string
loop

% Display Title
put " Report Card"
put " -------------"
put ""

% Ask For User Name
put " Enter Your Name "
put ""
get name
put ""

% Ask User For 4 Subjects
put " Enter Your 4 Subjects"
put ""

% Ask User For 4 Subject Marks
get sub1, sub2, sub3, sub4
put ""
put " Enter Your 4 Marks"

put ""
get mark1, mark2, mark3, mark4
cls


put " Report Card"
put " -------------"
put ""
put " Student Name : ", name
put ""
put " Subject Mark "
put " ", sub1, ": ", mark1, "%"
put " ", sub2, ": ", mark2, "%"
put " ", sub3, ": ", mark3, "%"
put " ", sub4, ": ", mark4, "%"
put ""
total := (mark1 + mark2 + mark3 + mark4) / 4
put " Your Average Is ", total, " % "
put ""
if total > 90 then
put " You Have An Exellent Average! "
if total > 80 then
put " Nice Average..."
if total > 70 then
put " You Know Your Stuff.."
if total > 60 then
put " Comon, You Can Do It! Try Harder!"
if total > 50 then
put " Comon, You Could Do It!!"
if total < 50 then
put " Man.. I have nothing to say to you.."
delay (10000)
cls
put " Would You Like To Calculate Another Average?"
put ""
get ans
end loop
exit when ans = "n" or ans = "N" or ans = "NO" or ans = "no"
end loop
end loop
Sponsor
Sponsor
Sponsor
sponsor
AsianSensation




PostPosted: Thu Oct 09, 2003 6:31 pm   Post subject: (No subject)

um........

You know that when you declare an if statement, you need an end if statement also?

ex.
code:
if a > 0 then
        blah blah blah
end if


So far, you haven't had one end if statement.
Tony




PostPosted: Thu Oct 09, 2003 8:25 pm   Post subject: (No subject)

yeah, you're missing end if

you should check out tutorials section and read how to propertly use if statments. More spesifically if - elseif - else structure.

Also - code indantation (F2 I think) helps you see where statments begin and where they end - makes it easier to read code and find bugs.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
hackman




PostPosted: Fri Oct 10, 2003 9:59 am   Post subject: (No subject)

I think this is what your looking for. The changes i made are underlined. Hope this helps.

% Date: 10/08/03
%
% Input: Subjects, Marks
% Output: Average, Marks, Name
% Process: Display Subjects, Get Average Of Marks
%
% ----------------------------------

colorback (black)
color
(brightgreen)
cls

% Declare All Variables
var mark1, mark2, mark3, mark4, total : real
var sub1, sub2, sub3, sub4, name, ans : string
loop

% Display Title
put " Report Card"
put " -------------"
put ""

% Ask For User Name
put " Enter Your Name "
put ""
get name
put ""

% Ask User For 4 Subjects
put " Enter Your 4 Subjects"
put ""

% Ask User For 4 Subject Marks
get sub1, sub2, sub3, sub4
put ""
put " Enter Your 4 Marks"

put ""
get mark1, mark2, mark3, mark4
cls


put " Report Card"
put " -------------"
put ""
put " Student Name : ", name
put ""
put " Subject Mark "
put " ", sub1, ": ", mark1, "%"
put " ", sub2, ": ", mark2, "%"
put " ", sub3, ": ", mark3, "%"
put " ", sub4, ": ", mark4, "%"
put ""
total := (mark1 + mark2 + mark3 + mark4) / 4
put " Your Average Is ", total, " % "
put ""
if total > 90 then
put " You Have An Exellent Average! "
elsif total > 80 then
put " Nice Average..."
elsif total > 70 then
put " You Know Your Stuff.."
elsiftotal > 60 then
put " Comon, You Can Do It! Try Harder!"
elsif total > 50 then
put " Comon, You Could Do It!!"
elsif total < 50 then
put " Man.. I have nothing to say to you.."
end if
delay (10000)
cls
put " Would You Like To Calculate Another Average?"
put ""
get ans
exit when ans="n" or ans="N" or ans = "NO" or ans = "no" then
end loop
Prince




PostPosted: Fri Oct 10, 2003 11:48 am   Post subject: (No subject)

u could also use case statements instead of an if statement... now that i think about it, since case and if statements r basically the same thing what's the purpose of using both Confused (other then case looks neater)
Dan




PostPosted: Fri Oct 10, 2003 12:54 pm   Post subject: (No subject)

well with case you have to comaper only one var but ifs and elese ifs they dont have to be using the same var.

cases are more for when you have somting where you know what the exicate or closee to input value will be for one var. i good place to use an case is for menus where the options are numbered or lettered.

but ifs can do anything cases can do and more so techanly there is no real need for cases but cases do make the code look nicer
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
coolest35




PostPosted: Fri Oct 10, 2003 4:45 pm   Post subject: RE: Code Revising

Thank You All For Your Response ! And An Extra Thank Yo Goes Out To " HACK MAN" Razz 8) Laughing
Andy




PostPosted: Sat Oct 11, 2003 2:31 pm   Post subject: (No subject)

u should just indent ur code and see where the problem is to indent press F2
Sponsor
Sponsor
Sponsor
sponsor
rizzix




PostPosted: Sat Oct 11, 2003 8:44 pm   Post subject: (No subject)

guys jeez do include all code in the [code ] ... [/ code] tags
hackman




PostPosted: Sat Oct 11, 2003 8:57 pm   Post subject: (No subject)

Sorey about that. I only did it(well, didn't do it) so coolest35 could read it better.
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  [ 10 Posts ]
Jump to:   


Style:  
Search: