Now, i input 1.5, obviously, it will show 1. But how can the program check that i just input 1.5 so that it will show an error for non integer input?

using namespace std;
int main(){
    int k;
    cout<<"Input: ";
    cout<< k ;

Recommended Answers

All 3 Replies

Why don't you use a float type to get the value and then check for non integer

The basic way is to save the input into a string and then check each character for validity.

you should use a float or double type instead int.
int just used for numbers without float point.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.