if you notice in your code you have: x += i;
This is saying in more simple terms: x = x + i;
i increments in 0.1 increments. So if you replace the variables with actual numbers (and assuming x = 0, you should always initialize your variables so you know what is in them at the start)
you get for the first few cases:
0 = 0 + 0.1 = 0.1; 1st case
0.1 = 0.1 + 0.2 = 0.3; 2nd case
0.3 = 0.3 + 0.4 = 0.7; 3rd case
0.7 = 0.7 + 0.5 = 1.2; 4th case
and so on and so forth. To do a count with the for loop there are a couple different ways to do it. First, in your code in the for loop you have:
1 2 3
|
for (i = 0.0; i <= 100; i+= .1) // this wont give you a count
// instead try this
for (i = 0.0; i <= 100; i) // this keeps i from incrementing allowing x to increment correctly
|
or you can use the code as Yumixfan gives you and just output i, but you want to modify it a little