As the name suggests, an integer holds integral data, numbers that have no fractional part. For this reason, it makes little sense to do any arithmetic with an integer where the fractional part is important; in this case, you should use floating point numbers. An example of this was shown in the last chapter:

    int height = 480;      int width = 640;     int aspect_ratio = width / height;

This gives an aspect ratio of 1, which is clearly untrue and serves no purpose. Even if you assign the result to a floating-point number, you will get the same result:

    float aspect_ratio = width / height;

The reason is that the arithmetic is performed in the expression width / height, which will use the division operator for integers that will throw ...

Get Beginning C++ Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.