+ 1

Need help here ?!

/*I try here to tell if number is odd or even it always print even*/ #include <iostream> using namespace std; int main() { float number=9 ; cout<<"Enter number to check if even or odd"; float x; x = number/2 ; int y; y = number/2 ; if (x==y) {cout<<"Even"; } else {cout<<"Odd"; } return 0; }

23rd Mar 2017, 6:27 PM
Kyrillos Akram
Kyrillos Akram - avatar
11 Réponses
+ 2
try taking float number =9.0 or x=number/2.0
23rd Mar 2017, 6:53 PM
Ritveak Dugar
Ritveak Dugar - avatar
+ 2
the condition u gave is wrong put x==y and it will work.😊
23rd Mar 2017, 7:08 PM
Ritveak Dugar
Ritveak Dugar - avatar
+ 2
plz follow me 😊
23rd Mar 2017, 7:15 PM
Ritveak Dugar
Ritveak Dugar - avatar
+ 2
done ^_^
23rd Mar 2017, 7:16 PM
Kyrillos Akram
Kyrillos Akram - avatar
+ 1
it is a nice code. but what help do u need?
23rd Mar 2017, 6:33 PM
Ritveak Dugar
Ritveak Dugar - avatar
+ 1
it always print even
23rd Mar 2017, 6:51 PM
Kyrillos Akram
Kyrillos Akram - avatar
+ 1
Error still up
23rd Mar 2017, 7:00 PM
Kyrillos Akram
Kyrillos Akram - avatar
+ 1
what if u try taking both ? float number =9.0 and x=number/2.0
23rd Mar 2017, 7:02 PM
Ritveak Dugar
Ritveak Dugar - avatar
+ 1
hey dude I got it... the condition u gave is wrong..... put x==y..... so dumb of me🤐
23rd Mar 2017, 7:03 PM
Ritveak Dugar
Ritveak Dugar - avatar
+ 1
i think when an odd divided by 2 fraction lost by int type
23rd Mar 2017, 7:07 PM
Kyrillos Akram
Kyrillos Akram - avatar
+ 1
fine ,i catch it now thank u :)
23rd Mar 2017, 7:14 PM
Kyrillos Akram
Kyrillos Akram - avatar