Code Revising
Author |
Message |
coolest35

|
Posted: 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 to insert END LOOP & END IF even though it is already in it :
% ----------------------------------
%
% 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

|
|
 |
AsianSensation
|
Posted: 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

|
Posted: 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. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
hackman
|
Posted: 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

|
Posted: 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 (other then case looks neater) |
|
|
|
|
 |
Dan

|
Posted: 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

|
Posted: 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" 8)  |
|
|
|
|
 |
Andy
|
Posted: 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

|
|
 |
rizzix
|
Posted: Sat Oct 11, 2003 8:44 pm Post subject: (No subject) |
|
|
guys jeez do include all code in the [code ] ... [/ code] tags |
|
|
|
|
 |
hackman
|
Posted: 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. |
|
|
|
|
 |
|
|