Author |
Message |
strugglin-angel
![](http://members.asianavenue.com/Ch/ChiTran88/rinoaangel.gif)
|
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? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
bugzpodder
![](http://www.vbforums.com/avatar.php?userid=31755&dateline=1038631511)
|
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 |
|
|
|
|
![](images/spacer.gif) |
strugglin-angel
![](http://members.asianavenue.com/Ch/ChiTran88/rinoaangel.gif)
|
Posted: Mon Feb 07, 2005 11:22 pm Post subject: (No subject) |
|
|
oooo i thot it had to b done with arrayz...~_~" thank you ! ^_^ |
|
|
|
|
![](images/spacer.gif) |
bugzpodder
![](http://www.vbforums.com/avatar.php?userid=31755&dateline=1038631511)
|
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. |
|
|
|
|
![](images/spacer.gif) |
Viper
![](http://compsci.ca/v3/uploads/user_avatars/20678142424cb7690e076fe.jpg)
|
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 |
|
|
|
|
![](images/spacer.gif) |
Delos
![](http://www.members.shaw.ca/rfolz/delos_avatar.gif)
|
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. |
|
|
|
|
![](images/spacer.gif) |
bugzpodder
![](http://www.vbforums.com/avatar.php?userid=31755&dateline=1038631511)
|
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 ... |
|
|
|
|
![](images/spacer.gif) |
Cervantes
![](http://compsci.ca/v3/uploads/user_avatars/1023105758475ab2e040bde.jpg)
|
Posted: Tue Feb 08, 2005 5:59 pm Post subject: (No subject) |
|
|
That's correct. It's not exit if |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
TheZsterBunny
![](http://www.members.shaw.ca/rfolz/zstervava2.jpg)
|
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 |
|
|
|
|
![](images/spacer.gif) |
strugglin-angel
![](http://members.asianavenue.com/Ch/ChiTran88/rinoaangel.gif)
|
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 |
|
|
|
|
![](images/spacer.gif) |
Martin
![](http://www.compsci.ca/wiki/images/4/46/CanadianStickUp.jpg)
|
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. |
|
|
|
|
![](images/spacer.gif) |
strugglin-angel
![](http://members.asianavenue.com/Ch/ChiTran88/rinoaangel.gif)
|
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 ^_^ |
|
|
|
|
![](images/spacer.gif) |
|