I don't see anything hard about implementing this. Your while loop looks right, you just have to do exactly what the question says. You need to get a number, check if that number plus your sum will be greater than 100; if it is, break out of the for-loop else add the number to sum
The loop will be less important than the conditional statements. The problem I see with relying on while(sum>100) (I think you meant (sum<100), BTW) is that it will continue to sum numbers until it's too late!
Say sum makes it up to 98, then the user inputs 6. Sum will become 104, then the conditional will check it.
int sum = 0;
while ( true )
{
std::cout << "Enter an integer number: ";
int x;
std::cin >> x;
if ( 100 - sum < x ) break;
sum += x;
std::cout << "The intermediate sum is equal to " << sum << std::endl;
}
std::cout << "\n\nThe result sum is equal to " << sum << std::endl;
#include<stdio.h>
int main(void)
{
int sum=0, num;
for(sum=0; sum <101;)
{
if(sum<101)
{
printf("Enter a number: ");
scanf("%d", &num);
sum = sum + num;
}
}
printf("Sum of number you enter is %d: ",sum);
return 0;
}