Pls help with error in c# can't convert string to int | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Pls help with error in c# can't convert string to int

I got an error 'can't convert string to int' but string is number. What to do? Help pls. https://sololearn.com/compiler-playground/cs4Q56FCueFX/?ref=app My code.

17th Mar 2024, 12:07 PM
KotaroTOP
KotaroTOP - avatar
3 Answers
+ 7
1.In Line no 14 you are "again" converting "FirstNum" variable of string type to int type and assigning it to SNum instead of doing that with "SecondNum" variable. 2.In Line no 48 in the default case you are assigning a string value to "Output" variable which is of type int.You can simply print the statement. 3.use break statement in default case too.
17th Mar 2024, 12:44 PM
𝘕𝘉
𝘕𝘉 - avatar
+ 3
I agree with NB‎. output was declared as int, but in line 48 you are assigning a string to it. yes, directly print the result. No need for the ouput variable. also, you have mixed up and duplicated cases.
17th Mar 2024, 1:10 PM
Bob_Li
Bob_Li - avatar
+ 3
NB, Bob_Li thank you very much :)
17th Mar 2024, 5:53 PM
KotaroTOP
KotaroTOP - avatar