I don't think the modulus (%
operator would be effective on non-integer input types. It could be a problem if the user wanted to use floating point values of some sort.
My understanding of this question is that the OP wants to know if the result is mathematically an integer - a positive or negative (or zero) number that has no fractional portion - not an integer in the C/C++ context.
Try the following. The number in question can be a floating-point or integer:
Code:
double number, number2, result;
long num;
cout << "Enter a number: ";
cin >> number;
number2 = number - 1;
result = number / number2;
num = (long) result;
if (result == num) cout << "result is an integer";
This may not be a completely effective solution, given the fact that floating point numbers can only approximate integer values, and are never exact. As I understand floating point data types, the only numbers that can be stored exactly are -1, 0, 1, and any power of 10 within the range of the type. I could be wrong about this, so don't take it as gospel truth or anything.