Hi everybody, I 'm new in C++ programming and when I was doing a program to extract the integer part of a number, and also write the directly superior integer to it, and the directly inferior integer to it. For example:
I: 4.5
O: 4 5 5
I use the module operation (%) to determine wheter the number is integer or not, but i get an error I think I should not be getting:
[Error] invalid operands of types 'float' and 'int' to binary 'operator%'
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
usingnamespace std;
int main () {
float d;
cin >> d;
int r = int(d); // get integer part which will be used as inferior integer part
int esup = r + 1; // superior integer part
int eprox;
if (d%r != 0) eprox = esup; // determine wheter d is integer. If it isn't, his closest integer is superior integer..
else esup = r; // if it is integer, the closest integer is his own integer part.
cout << r << " " << esup << " " << eprox << endl;
}