if you have a loop that asks for the user to input a value and the loop doesn't end until the sentinal, how can you keep track of all the values entered and add them together?

Printable View

- 04-09-2008marquis1431keeping track of values
if you have a loop that asks for the user to input a value and the loop doesn't end until the sentinal, how can you keep track of all the values entered and add them together?

- 04-09-2008Dave_Sinkula
A sum and an input?

- 04-09-2008marquis1431
i.e. scanf("%d", &d)...if this is in a loop an dthe user enters values 5, 8, & 9 how do you write the language to add these together....i.e. add first loop u have 5, next loop you add 5 to 8, next loop you add 13 to 9....how do you write that?

- 04-09-2008Dave_SinkulaCode:
`sum = 0;`

while ( scanf("%d", &d) == 1 )

{

sum += d;

}