+ 1
I was just writing a code to check whether a number is rational or irrational,please check where are the errors
// For checking whether an input is rational or irrational #include <iostream> using namespace std; int main() { float num; cout<<"Enter the number to check : "; cin>>num; float remainder=num%1; cout<<num<<endl; if(num%1==0){ cout<<"The number is Rational and Integer";} if(remainder%1=remainder){ cout <<"The number is Rational but its decimal representation is repeating";} else {cout <<"It is an Irrational number";} return 0; }
3 odpowiedzi
+ 3
The modulo operator % only works with integral type operands. If you need to work with floating point type operands, then you will need to use `fmod` function from <cmath> header.
http://www.cplusplus.com/reference/cmath/fmod/
+ 3
You cannot use assignment operator in if statement!
Use this '=='
+ 2
Thank you Ipang and Namit Jain