Computer Science Canada how do i find the sum of all numbers ? |
Author: | strugglin-angel [ Mon Feb 07, 2005 11:05 pm ] |
Post subject: | how do i find the sum of all numbers ? |
how do i write a program that will find the sum of all numbers until an EOF of -99 is entered? |
Author: | bugzpodder [ Mon Feb 07, 2005 11:12 pm ] |
Post subject: | |
this is best done using a 'loop' loop. have an 'exit when' condition when EOF -99 occurs |
Author: | strugglin-angel [ Mon Feb 07, 2005 11:22 pm ] |
Post subject: | |
oooo i thot it had to b done with arrayz...~_~" thank you ! ^_^ |
Author: | bugzpodder [ Tue Feb 08, 2005 11:13 am ] |
Post subject: | |
right, you dont really need an array. the only thing you need to keep track of is the sum. |
Author: | Viper [ Tue Feb 08, 2005 1:02 pm ] |
Post subject: | |
ull need the sum and the number of inputs not including the -99 eg loop put "enter num" get num exit if num=-99 sum:=sum+num numcount:=numcount+num end loop |
Author: | Delos [ Tue Feb 08, 2005 3:14 pm ] | ||
Post subject: | |||
Viper, you've been around long enough to know 2 things: 1) Use [code ] tags. That's just a given. 2) "sum:=sum+num" I'm not even going to breach upon commenting on your formatting. That entire statement can be condensed to
Keeping in mind that 'sum' has to be initialized at its onset. |
Author: | bugzpodder [ Tue Feb 08, 2005 5:55 pm ] |
Post subject: | |
okay, i know i havent used turing in a while, but shouldnt it be: exit when ... |
Author: | Cervantes [ Tue Feb 08, 2005 5:59 pm ] |
Post subject: | |
That's correct. It's not exit if |
Author: | TheZsterBunny [ Tue Feb 08, 2005 8:16 pm ] |
Post subject: | |
... arrays? ... this program you're writing should be way before you need to worry about arrays. good luck anyways. -Z |
Author: | strugglin-angel [ Tue Feb 08, 2005 10:58 pm ] |
Post subject: | |
lol thanx guyz y'all have been very helpful ^_^ ....and for arrays...lol i don't even noe wa dey are wa was i thinkin ~_~" lol i'm so nub =p |
Author: | Martin [ Tue Feb 08, 2005 11:40 pm ] |
Post subject: | |
Just think about it as if you were doing the problem yourself. "I'm going to give you an indeterminate number of numbers, and I need you to tell me the sum." The best way to do this would simply be to keep a running total. |
Author: | strugglin-angel [ Wed Feb 09, 2005 12:00 am ] |
Post subject: | |
hmm dats a very logical way of thinkin of it hmm u guyz are soo gud at this .. i just mite pass comp sci this semester ^_^ |