0

hello am new here.. can somebody tell me if there's a restriction for a decimal numbers entered? for instance,

cout<<"Enter number: "
cin>>num;

--- if the user put a decimal number on the variable num..
i want this to be INVALID INPUT in the terminal screen as a result.

any idea please.. it's c++.. thanks!

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by firstPerson
0

hello am new here.. can somebody tell me if there's a restriction for a decimal numbers entered? for instance,

cout<<"Enter number: "
cin>>num;

--- if the user put a decimal number on the variable num..
i want this to be INVALID INPUT in the terminal screen as a result.

any idea please.. it's c++.. thanks!

before you can use narue's solution your 'num' variable has to of correct type. Because your checking if cin failed means that your num variable has to be of a type that does not support reading in floating numbers, for example if 'num' was of type char then entering in decimal number would fail it. But if it was like a std::string or char array or any floating or integral type then it wouldn't fail.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.