Like kbw said, use a float(floating point number). A float (or it's bigger cousin the double) is the computer's way of storing decimal numbers. In your code you try to store decimal numbers in an integer, but they will just get "trunctuated" to zero, since floats are always rounded down on casting to int:
1 2 3 4 5 6 7 8 9 10
|
#include <iostream>
int main()
{
int a = 0.1;
int b = 0.9;
int c = 1.1;
std::cout<<a<<":"<<b<<":"<<c;
std::getchar();
}
|
If you try compiling this program you'll see that both a and b end up as zero. Instead, use a float to store the values:
1 2 3 4 5 6 7 8 9 10
|
#include <iostream>
int main()
{
float a = 0.1;
float b = 0.9;
float c = 1.1;
std::cout<<a<<":"<<b<<":"<<c;
std::getchar();
}
|
Now you should be seeing the right values being output. One downfall to floats is that they aren't perfectly precise, and some values can not be represented perfectly. For example, from Wikipedia:
"The representable number closest to 0.01 is
0.009999999776482582092285156250 exactly."
So if you need high precision, be very careful about floats, and always remember that they can introduce error into your code. Doubles use twice the number of bits as floats, and as such have "double" the precision, which can help but is still not perfect.