+ 1

How to check the input is numbers or not?? (In c++)

14th Jun 2019, 2:52 PM
kajamohan
kajamohan - avatar
4 Réponses
+ 1
string s; cin>>s; int num = 0; for (int i = 0; i<s.length(); i++){ if(isdigit(s[i])){ num += 1; } } if(num==s.length()){ cout << "Number"; } else { cout << "Not a number"; }
15th Jun 2019, 6:37 PM
Choe
Choe - avatar
+ 1
language?
14th Jun 2019, 2:56 PM
Cat Sauce
Cat Sauce - avatar
+ 1
C++
14th Jun 2019, 3:02 PM
kajamohan
kajamohan - avatar
+ 1
Thanks
6th Jul 2019, 2:43 PM
kajamohan
kajamohan - avatar