Decimal Error

Whenever I use decimals in my code, it doesn't work. Is it perhaps the IDE I'm running it on? Or perhaps is it because I'm on a Mac?

I'm running it on Code::Blocks on a Mac.

The code is..
1
2
3
4
5
6
7
8
9
10
    int x;
    for (x=10; x<=20; x+.1)
    {
        cout << x << endl;
        if (x == 15)
        {
            cout << "The loop has been broken before it's reached 20!" << endl;
            break;
        }
    }


This is not the complete code. This is part of a really messy 100ish line code I'm using as my testing code. There are no errors building it or running it, however, while it's running the loop never ends. It continues to print out 10 rather than 10.1.
x is an integer so it won't increment by a fractional amount, so in your for loop x will never raise above 10.
x is an int. An int. That means it's an integer. Integers do not have decimal places.
you need a float rather than an int, it will just round to the nearest number unless it's a float
Last edited on
Topic archived. No new replies allowed.