Posted: Tue May 31, 2005 6:53 pm Post subject: Arrays And Counter -
Hi
I have to create program using array and counters that asks the user to input a bunch of numbers(marks)from 0-10 and as soon as a certain value is entered (such as -45) then the program stops asking the user to input a mark and displays how many students in this case has the same mark (2 students have 4 marks if you enter 4 twice etc.) So far i have done the following but I don't know is the what becomes strint(l) after the error trap code is finished.Please help!
code:
var c:array0..10 of list
var l: string
put "Please enter the marks."
loop
get l: *
if l >="0" and <="9" then
exit
elsif l>="a" and <="z" then
put "error"
elsif l ="-99" then
exit
else
put "error"
end if
end loop
???=strint(l)
Sponsor Sponsor
wtd
Posted: Tue May 31, 2005 7:23 pm Post subject: (No subject)
Let's clean that up a bit.
Turing:
var c :array0..10of list
var l :string put"Please enter the marks." loop get l: * if(l >= "0"and l <= "9")or l ="-99"then exit else put"error" endif endloop
??? =strint(l)
Now, it seems you've got a decent grip on checking for good input.
Let's move that into a function.
Turing:
function getGrade :int var l :string var i :int loop get l: * ifstrintok(l)then
i :=strint(l) if i >= 0and i <= 100then result i
else put"error" end else put"error" endif endloop end getGrade
Does this make sense?
[Gandalf]
Posted: Wed Jun 01, 2005 11:02 am Post subject: (No subject)
wtd, you're using functions a lot now, not sure if everyone will understand .
Also, you're missing an "if" after "end"
It should be:
code:
function getGrade : int
var l : string
var i : int
loop
get l: *
if strintok (l) then
i := strint (l)
if i >= 0 and i <= 100 then
result i
else
put "error"
end if
else
put "error"
end if
end loop
end getGrade
wtd
Posted: Wed Jun 01, 2005 12:36 pm Post subject: (No subject)
[Gandalf] wrote:
wtd, you're using functions a lot now, not sure if everyone will understand .
Also, you're missing an "if" after "end"
Thanks for catching that.
And they should understand functions. Functions are critical and the only way to "get" them is to see them used and to use them.