+ 1

How can I do typecasting in 'password'

I created an ATM_System in c++. There is a variable 'password' of type 'int'. If the user enters any string instead of an integer value, the program will keep on running. Is typecasting is its solution? If yes, how can I do it?

26th Mar 2020, 2:43 PM
Mehwish G R
Mehwish G R - avatar
7 Respostas
+ 3
Yeah, exactly I want so. I don't know how to share a code link here. Can you please explain?
26th Mar 2020, 3:08 PM
Mehwish G R
Mehwish G R - avatar
+ 2
thank you very much
26th Mar 2020, 11:21 PM
Mehwish G R
Mehwish G R - avatar
+ 1
Do you want this 'password' to accept only numbers or the other way around? (accepts any character). Why didn't you share the code link along with the thread Description?
26th Mar 2020, 2:51 PM
Ipang
+ 1
To share a code, first you gotta have a copy of the code saved in SoloLearn. And then ... If you're on mobile, open the code in Playground, tap that share button on top right corner, choose "Copy to clipboard". If you're on web, open the code in Playground, and copy the URL in the browser's address bar. Now you have a link to the saved code in clipboard, you can paste it where it is needed. If you paste it in the thread Description people can see it on sight. I'll be back ...
26th Mar 2020, 3:20 PM
Ipang
+ 1
It is rather difficult to actually "force" the input to be in numeric format. I guess the best we could do, for this case (and in console) was to accept the input as string, and then check each character for validity. Or accept input as number and check input stream state after reading input, to see if all went well.
26th Mar 2020, 3:30 PM
Ipang
26th Mar 2020, 4:11 PM
Mehwish G R
Mehwish G R - avatar