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
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?
A sum and an input?
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?
Code:sum = 0;
while ( scanf("%d", &d) == 1 )
{
sum += d;
}