How do i make this code say error when wrong input is done | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How do i make this code say error when wrong input is done

https://code.sololearn.com/cz06V5V2OmAE/?ref=app

16th Jun 2017, 11:22 PM
Smiler Kiss
Smiler Kiss - avatar
5 Answers
+ 2
Inclose the code in an if else statement that if ( x is right) then .... else {error}
17th Jun 2017, 1:50 AM
NulledNVoided
NulledNVoided - avatar
+ 2
i dont understand
21st Jun 2017, 9:36 PM
Smiler Kiss
Smiler Kiss - avatar
+ 2
ok
13th Aug 2017, 5:59 PM
Smiler Kiss
Smiler Kiss - avatar
+ 1
I have not worked with CS but is there something like a try: except: to try ... if error ...
22nd Jun 2017, 2:36 AM
NulledNVoided
NulledNVoided - avatar
0
You can handle a wrong input with try catch: try{ BankAccount b = new BankAccount(); b.Deposit( Convert.ToInt32(Console.ReadLine())); b.Withdraw( Convert.ToInt32(Console.ReadLine())); Console.WriteLine("Your balance :"+(b.GetBalance())); }catch(Exception e) { Console.WriteLine("Wrong Input! "); }
13th Aug 2017, 4:50 PM
Stephan