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); } } }
6 Answers
+ 4
Матвей Ярмак ok, seems to have an extra space in "Console.ReadLine ()" and should be "Console.ReadLine()" without the space before the parentheses
+ 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
+ 1
OMG. Thank You!
0
x will always be 1!
What do you want to achieve exactly?
Increase the levels or...?
0
Why code not even running
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.");
}
}
}
}