# sum of integers

this should sum the integers from 100 to 150, assuming the total is initialized to 0.....but its not

for ( x = 100; x <= 150; x++ )
total += x;

whats wrong? thanks

• [b][red]This message was edited by Vilanye at 2005-6-30 21:14:4[/red][/b][hr]
: this should sum the integers from 100 to 150, assuming the total is initialized to 0.....but its not
:
: for ( x = 100; x <= 150; x++ )
: total += x;
:
: whats wrong? thanks
:
total is not initialized to 0? If you want it to start at 0, then start it at 0.

You need to post a lot more code and give specifics. Whats wrong is not enough. Haven't enough people made this clear to you yet?

1. If you get syntax errors, READ THEM. They will tell you the problem and the line number. Just be aware that sometimes the line numbers are a bit off due to parsing issues. If you can't figure out what they mean, post all the code, and the syntax errors.

2. If the output is not what you expect or you don't understand it. Trace your program on paper, or using a debugger. On small programs, paper is a bit easier and makes things clearer. Put in printf() or assert statements to check what certain variables are doing at certain points in the execution. If you are can't figure out what a line does, ask or consult a book.

The reason people lose patience with you is that it is obvious you are putting very little effort into the learning process, which is why, weeks later you are asking the same types of questions.

• : this should sum the integers from 100 to 150, assuming the total is initialized to 0.....but its not
:
: for ( x = 100; x <= 150; x++ )
: total += x;
:
: whats wrong? thanks
:
[code]#include <stdio.h>

int main(void)
{
int i, sum; sum = 0;

for(i = 100; i <= 150; i++)
sum += i;

printf("%d", sum);

return (0);
}[/code]If your compiler can't handle the above, then I'd look for another compiler.