I cant understand what's wrong | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I cant understand what's wrong

Cant find the mistake at all namespace Sololearn { class Program { static void Main(string[] args) { int levels = Convert.ToInt32(Console.ReadLine ()); int x = levels - levels + 1; Console.WriteLine ("{0}", x); } } }

23rd Aug 2023, 11:18 AM
Матвей Ярмак
Матвей Ярмак - avatar
6 Answers
+ 4
Матвей Ярмак ok, seems to have an extra space in "Console.ReadLine ()" and should be "Console.ReadLine()" without the space before the parentheses
23rd Aug 2023, 4:19 PM
Jhordy Gavinchu
Jhordy Gavinchu - avatar
+ 2
the calculation of x seems to be wrong, you are calculating "levels - levels" so it will always be 0 and the input value is never used
23rd Aug 2023, 12:45 PM
Jhordy Gavinchu
Jhordy Gavinchu - avatar
+ 1
OMG. Thank You!
23rd Aug 2023, 4:21 PM
Матвей Ярмак
Матвей Ярмак - avatar
0
x will always be 1! What do you want to achieve exactly? Increase the levels or...?
23rd Aug 2023, 1:36 PM
Samir Krasnic
Samir Krasnic - avatar
0
Why code not even running
23rd Aug 2023, 1:43 PM
Матвей Ярмак
Матвей Ярмак - avatar
0
Woth your code you got String error. Bcs there is possibility that user enters Name and that can't be converted to int,so you get an exception. Since you need to increase lvl number you have to take a NUMBER as Input. try this code: using System; namespace NumberInputExample { class Program { static void Main(string[] args) { Console.WriteLine("Please enter an integer:"); string input = Console.ReadLine(); // Read user input as a string // Convert the string to an integer if (int.TryParse(input, out int intValue)) { Console.WriteLine("You entered: " + intValue); } else { Console.WriteLine("Invalid input. Please enter a valid integer."); } } } }
23rd Aug 2023, 2:18 PM
Samir Krasnic
Samir Krasnic - avatar