I have a code which should check the number before and after the comma. If these numbers are equal, the program writes out '1', otherwise - '0'.
float num, pnum;
std::cout << "num = ";
std::cin >> num;
pnum = num - int (num);
for (int i = 0; i < 7; i++) {
pnum = pnum * 10;
}
while (int (pnum) % 10 == 0) {
pnum = pnum / 10;
}
if (int (num) == int (pnum)) {
std::cout << "1\n";
} else {
std::cout << "0\n";
}
Results:
num = 2.2
output = 1
num = 22.22
output = 0
why?
note: I don't want to use strings in this program