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

Username:   Password: 
 RegisterRegister   
 Arrays And Counter -
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
silent_k




PostPosted: 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
Sponsor
sponsor
wtd




PostPosted: Tue May 31, 2005 7:23 pm   Post subject: (No subject)

Let's clean that up a bit.

Turing:
var c : array 0..10 of 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"
   end if
end loop
??? = 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: *
      if strintok (l) then
         i := strint (l)
         if i >= 0 and i <= 100 then
            result i
         else
            put "error"
         end
      else
         put "error"
      end if
   end loop
end getGrade


Does this make sense?
[Gandalf]




PostPosted: 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 Smile.

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




PostPosted: 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 Smile.

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.
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  [ 4 Posts ]
Jump to:   


Style:  
Search: