Computer Science Canada

example problem??? I'm totally lost!

Author:  cutiegirl_14_16 [ Thu Mar 06, 2003 8:25 pm ]
Post subject:  example problem??? I'm totally lost!

ok so here's the program
assuming that the variables are already declared

loop
put "Enter a number. To end the program type stop"
exit when number=-999
count:=count+1
end loop
put "The number of number's entered is", count


How do u change the program to read the series of numbers and determine the total sum of the numbers entered.

help would be great!!!!!!!

Author:  Tony [ Thu Mar 06, 2003 8:30 pm ]
Post subject: 

same thing, but instead of counting how many number were entered (+1 through each run) you add up the total (current total + number entered)

so

code:
loop
put "Enter a number. To end the program enter -1"
get number
exit when number=-1
total := total + number
end loop

put "the total is: ", total


it should be -1 instead of "stop" because that way you'd have to get input as string and convert it to integer with strint() and its extra work... so just -1 or 0 or w/e other number you dont think user would use.

Author:  cutiegirl_14_16 [ Thu Mar 06, 2003 8:35 pm ]
Post subject: 

thanx...ur a life saver....twice!

Author:  Tony [ Thu Mar 06, 2003 8:36 pm ]
Post subject: 

Very Happy no problem, thats what this site is for Wink


: