0
Can any one fix the problem in this calculator?
14 Antworten
+ 2
Piyush Duggal read the answer of ~ swim ~, the problem is in the way the input is taken. Since SL takes the input at the beginning of the execution, a blank text will be input for all the following cases where no input was given.
Which means you code in fact is calculating the first two numbers entered, and giving the first result correct. But then, it considers empty texts as input, and converting an empty text to int will return 0.
Which means you program is actually working, it calcultes 0+0 an infinite amount of time.
+ 6
It's a kind of converting method
Just like this code:
Int x=int32.TryParse(Console.ReadLine());
You can read more in this page:
https://www.dotnetperls.com/parse
+ 5
You should use the "TryParse()" method to initializing the variables
+ 2
It does it job just fine. You should specifiy a "quit" command, otherwise the loop will never stop.
+ 2
Make x a string, and not an int. If the user inputs "quit", you break the loop. If the input is not "quit", only then convert x to an int.
+ 2
Piyush Duggal since I didn't ask first, what is the problem then? I though the problem was the infinite loop, but apparently it isn't. I tested the code, and it seems to work perfectly fine.
+ 1
Piyush Duggal here is the code:
https://code.sololearn.com/cwC9cQ5JGEu5/?ref=app
+ 1
Piyush Duggal no problem 👌
+ 1
Please don't use irrelevant tag
0
I Don't know how to make "quit" command!
0
Nothing happened
0
The code is showing like this
x = y = result : 34
x = y = result : 0
x = y = result : 0
And so on,
Is this Infinite loop, isn't it?
0
WooW thanks, 👍👍