# Thread: a sum equal to or in excess of 100

1. ## a sum equal to or in excess of 100

Code:
```#include <stdio.h>
int main (void)
{
int value, sum = 0;

printf ("Enter a value: ");
scanf ("%i", &value);

while ( sum > 100 )
{
scanf ("%i", &value);
}
while ( (value < 0) || (value > 25) )
{
printf ("Out of range, please re-enter: ");
scanf ("%i", &value);
}

sum = sum + value;
printf ("\nThe sum is: %i\n\n", sum);

return 0;
}```
This program is to take user entered integers ranging from 0 to 25 until the sum of those entered integers is equal to or in excess of 100. I know the 0 to 25 constraint works fine, it's the sum part that isn't so fine.

Currently what the program does is it takes the first acceptable entered integer and just prints that as the sum as well. Ex: if I input 25 it will say the sum is 25.

It should keep asking for numbers until a sum of 100 or greater is reached. 2. while ( sum > 100 )
I only started learning C yesterday, but I think that that should be:
while ( sum < 100 )
...because you want that loop to repeat until the sum is >= to 100.

I might be wrong though. I have less than 1 month of programming experience so yeah... 3. Xlayer- I tried your suggestion and it appears to have made matters worse. Doing that destroys my constraint checking loop and the program just keeps accepting numbers regardless and with no end.

I'm a beginning programmer too, no worries.

Edit: Would you mind pointing out these errors to me? Maybe changing those errors will make your solution work. 4. Presumably, to work, the accumulation of sum (sum = sum + value; which can also be expressed as sum += value;) needs to be within the loop that checks the value of sum. 5. Do you understand what each line of code does? Do you understand the way while loops work? 6. You're checking the value of sum when sum is 0.... I don't get it. Think about what you're doing. It's most likely not what you want. Set sum first and then go ahead and check its value. 7. Yeah, you have 2 separate loops. I would re-think how you are solving this problem. You could write this program, with one loop that executes until the sum equals or is greater than 100. Also, are you supposed to print the sum after each number is inputed or only, after the sum exceeds or is equal to 100? Also I would prompt the user for the first number and then also, prompt the user for the rest of the values because it would be confusing for anyone using your program. You could also just prompt the user once by saying: "Enter integers separated by pressing enter until the sum is >= to 100." Or better yet, write your own prompts so it isn't so hard to understand (I am a bad writer). Also, consider Just Prompting with "Enter a Number" for the first time and then "Enter Another Number" for each time leading up to the sum being >= to 100. Popular pages Recent additions 