Agree with gurukrupa, you forgot to print out your result.
What I feel about your program is that:
I was hungry.
I bought my food, but I did not eat it.
I found myself still hungry.
Apply to your code:
You are trying out while loop.
You coded the while loop, but I did not print out the numbers that shows while loop is working.
You thought that while loop was wrong.
"Could you please tell me why (your 4th statement) will be eliminated by the compiler?"
Because total and count do not affect the program (no noticeable side-effects). Therefore, the compiler will see it as a waste of processing time, and will optimise it away. However, if you used total and count in a way that affects the program (such as opening a file, writing to the output buffer, or using it to store input), the compiler cannot ignore that and the code will remain (optimising away the code would break the program).
Too many lines of code that to calculate number * number. And moreover even this simple operation the program does incorrectly because if the number will be enetered as negative the sum will be equal to zero.:)
The loop has no function. It does not output the numbers or the result of the calculation.
Secondly, what is the program supposed to do?
total = total + number will give you a multiple of whatever number is. If number is 5 total will be (counter:total) 0:5 1:10 2:15 3:20 4:25. The value of number does not change in the loop.
If you are trying to total up the values untill you get to number for instance 1+2+3+4....number then it should be total = total + counter.
to see the effect put cout >> total in the loop after the calculation.
it's poor style creating variables before they are needed
i don't understand, i don't see variables are created before they are needed... what i saw, is the variable creation is done exactly when they needed...