How to make my programme reject floating point numbers within an if statement? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to make my programme reject floating point numbers within an if statement?

I want my programme to reject any floating point number input. Please show me your way...xd https://code.sololearn.com/cig2XjrnuRlW/?ref=app

30th Jan 2019, 2:13 AM
Tecolote Come Elote
Tecolote Come Elote - avatar
3 Answers
+ 4
Take a float and check if it has decimal numbers by checking the equality with the number and its own floor. Then you convert it to an integer. Anyway, I would suggest you making some advice when you are asking for the user input.
31st Jan 2019, 10:05 PM
Skarline 🌟
Skarline 🌟 - avatar
+ 1
By default if you use cin to put value into integer it "cuts" floating point numbers. So for example if you put 14.56 program will convert it into 14 and put it to your variable.
30th Jan 2019, 9:27 AM
Jakub Stasiak
Jakub Stasiak - avatar
+ 1
But Is there a way to make the programme print "I didnt ask for a floating point number" if they so so?
31st Jan 2019, 10:00 PM
Tecolote Come Elote
Tecolote Come Elote - avatar