0

Can any one fix the problem in this calculator?

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

17th Feb 2020, 10:18 AM
Piyush Duggal
Piyush Duggal - avatar
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.
17th Feb 2020, 10:44 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 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
19th Feb 2020, 4:31 AM
P. T
P. T - avatar
+ 5
You should use the "TryParse()" method to initializing the variables
17th Feb 2020, 6:57 PM
P. T
P. T - avatar
+ 2
It does it job just fine. You should specifiy a "quit" command, otherwise the loop will never stop.
17th Feb 2020, 10:23 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 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.
17th Feb 2020, 10:26 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 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.
17th Feb 2020, 10:39 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
17th Feb 2020, 10:30 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
Piyush Duggal no problem 👌
17th Feb 2020, 10:49 AM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 1
Please don't use irrelevant tag
17th Feb 2020, 10:59 AM
Gordon
Gordon - avatar
0
I Don't know how to make "quit" command!
17th Feb 2020, 10:24 AM
Piyush Duggal
Piyush Duggal - avatar
0
Nothing happened
17th Feb 2020, 10:37 AM
Piyush Duggal
Piyush Duggal - avatar
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?
17th Feb 2020, 10:42 AM
Piyush Duggal
Piyush Duggal - avatar
0
WooW thanks, 👍👍
17th Feb 2020, 10:48 AM
Piyush Duggal
Piyush Duggal - avatar