First, please use the code tags and indentation, when posting code.
See http://www.cplusplus.com/articles/jEywvCM9/
The nice formatting really improves readability and line numbering makes commenting the code simpler.
#include<iostream>
int main()
{
std::cout << "enter a number: ";
int num;
std::cin >> num;
int sum = 0
int a;
for ( a=1; a <= num; ++a )
{
sum = sum + a;
if ( num < sum )
{
break;
}
}
std::cout << (a-1);
return 0;
}
I kind of feel bad for just giving you the answer; however, like everyone else said...What exactly were you trying to do. I saw you had comments out on 1+2+3+4 < 10 (10 isnt greater than or less than 10, it's ==)TRUE....vice versa for your other comment..It seems to me like it was asking you for four integer values. Im not exactly sure why you wanted to use a for loop or even an if statement. Unless you are trying to say if the answer of the sum from the four numbers isnt 10 then cout >> "what ever code you wanted to put in here"....
PS... In your for loops I believe Ive seen quite a few people mention that it's good practice to do ++x when doing increments of instead of x++. Just a suggestion....