0

How to validate my input? the input is positive number, if i put character or negative number, it will send me output error

11th Nov 2020, 12:55 PM
HĂ o Đáș·ng
3 Answers
+ 2
If you need to fix input errror in c++ Then check this out https://code.sololearn.com/c0P5ih7rx08Q/?ref=app
11th Nov 2020, 1:17 PM
Muhammad Atif Waheed
Muhammad Atif Waheed - avatar
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.
11th Nov 2020, 1:08 PM
äœ çŸ„é“èŠć‰‡ïŒŒæˆ‘äčŸæ˜Ż
äœ çŸ„é“èŠć‰‡ïŒŒæˆ‘äčŸæ˜Ż - avatar
0
Tks bro, i will try
11th Nov 2020, 2:32 PM
HĂ o Đáș·ng