+ 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; }

27th Sep 2020, 5:34 AM
Aquib
Aquib - avatar
3 Answers
+ 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/
27th Sep 2020, 5:43 AM
Ipang
+ 3
You cannot use assignment operator in if statement! Use this '=='
27th Sep 2020, 5:47 AM
Namit Jain
Namit Jain - avatar
+ 2
Thank you Ipang and Namit Jain
27th Sep 2020, 6:14 AM
Aquib
Aquib - avatar