newbie help

This is a discussion on newbie help within the C Programming forums, part of the General Programming Boards category; Just started C programming, and I'm trying to make this little code. I'm guessing you guys know what its point ...

The problem is when I run this the "count" vcariable always equals "input". Why is it so, I mean I did the if statement so that the count increases only if input % x == 0. A bit confusing . Thanks in advance

>The problem is when I run this the "count" vcariable always equals "input".
Of course it does, the loop iterates input times, and because count starts out at 0, it will be equal to input - 1 on the last iteration and input after the loop ends. Walk through the code, it makes sense.

>I mean I did the if statement so that the count increases only if input % x == 0.
Ah, but you didn't. If an if statement body is not surrounded by braces then only the next statement will be part of the body. Properly indented, your loop looks like this:

>I'm guessing you guys know what its point is since ur all expererts
What I wouldn't give to be able to understand code at a glance. Knowing what each piece does isn't the same as understanding how they work together as a whole. The former is easy, the latter takes a bit of staring even for simple programs.

>statement implicitly is understood to come at the end of the main() function
This is only true of the C99 standard, which is not widely implemented enough to assume at this point. Therefore, we assume C89, where omitting a return value is undefined.