0
How to validate my input? the input is positive number, if i put character or negative number, it will send me output error
3 ответов
+ 2
If you need to fix input errror in c++
Then check this out
https://code.sololearn.com/c0P5ih7rx08Q/?ref=app
0
scanf() returns int, it returns total of input successfully handled. For example: scanf("%d%d") requires user to input 2 ints. If the user input 2 ints, scanf() returns 2. If the user only input 1 int, it returns 1.
You can use if(scanf("%d", &num) == 0) to validate the non-integer input
You then can use if(num > 0) to check if num is positive.
0
Tks bro, i will try