Author |
Message |
strugglin-angel
|
Posted: 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? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
bugzpodder
|
Posted: Mon Feb 07, 2005 11:12 pm Post subject: (No subject) |
|
|
this is best done using a 'loop' loop. have an 'exit when' condition when EOF -99 occurs |
|
|
|
|
|
strugglin-angel
|
Posted: Mon Feb 07, 2005 11:22 pm Post subject: (No subject) |
|
|
oooo i thot it had to b done with arrayz...~_~" thank you ! ^_^ |
|
|
|
|
|
bugzpodder
|
Posted: Tue Feb 08, 2005 11:13 am Post subject: (No subject) |
|
|
right, you dont really need an array. the only thing you need to keep track of is the sum. |
|
|
|
|
|
Viper
|
Posted: Tue Feb 08, 2005 1:02 pm Post subject: (No 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 |
|
|
|
|
|
Delos
|
Posted: Tue Feb 08, 2005 3:14 pm Post subject: (No 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. |
|
|
|
|
|
bugzpodder
|
Posted: Tue Feb 08, 2005 5:55 pm Post subject: (No subject) |
|
|
okay, i know i havent used turing in a while, but shouldnt it be:
exit when ... |
|
|
|
|
|
Cervantes
|
Posted: Tue Feb 08, 2005 5:59 pm Post subject: (No subject) |
|
|
That's correct. It's not exit if |
|
|
|
|
|
Sponsor Sponsor
|
|
|
TheZsterBunny
|
Posted: Tue Feb 08, 2005 8:16 pm Post subject: (No subject) |
|
|
...
arrays?
...
this program you're writing should be way before you need to worry about arrays.
good luck anyways.
-Z |
|
|
|
|
|
strugglin-angel
|
Posted: Tue Feb 08, 2005 10:58 pm Post subject: (No 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 |
|
|
|
|
|
Martin
|
Posted: Tue Feb 08, 2005 11:40 pm Post subject: (No 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. |
|
|
|
|
|
strugglin-angel
|
Posted: Wed Feb 09, 2005 12:00 am Post subject: (No 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 ^_^ |
|
|
|
|
|
|