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

Username:   Password: 
 RegisterRegister   
 how do i find the sum of all numbers ?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
strugglin-angel




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




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




PostPosted: Mon Feb 07, 2005 11:22 pm   Post subject: (No subject)

oooo Very Happy i thot it had to b done with arrayz...~_~" thank you ! ^_^
bugzpodder




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




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




PostPosted: 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
code:

sum += num

Keeping in mind that 'sum' has to be initialized at its onset.
bugzpodder




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




PostPosted: Tue Feb 08, 2005 5:59 pm   Post subject: (No subject)

That's correct. It's not exit if
Sponsor
Sponsor
Sponsor
sponsor
TheZsterBunny




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




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




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




PostPosted: Wed Feb 09, 2005 12:00 am   Post subject: (No subject)

Idea hmm dats a very logical way of thinkin of it Very Happy hmm u guyz are soo gud at this .. i just mite pass comp sci this semester ^_^
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  [ 12 Posts ]
Jump to:   


Style:  
Search: