+ 1
I don't understand why my program is not working properly. If I enter 10, then the program will give me not 11 but 101, why?
8 Antworten
+ 4
Иван Литовченко , the variable x is string, so the operation is string concatenation => "10" + 1 => "101". You can declare x as int => int x =int.Parse(Console.ReadLine ()).
+ 2
Иван Литовченко , you didn't assign it to a variable => int y = Convert.ToInt32 (x);
+ 1
But I wrote Convert.Toint32, he had to convert x to int ?
+ 1
int x = Convert.ToInt32(Console.ReadLine());
+ 1
static void Main(string[] args)
{
int x = int.Parse(Console.ReadLine());
x+=1;
Console.WriteLine (x);
}
+ 1
Instead of making x a string make it a int
Get the input from user , since its a string type cast it to a int with the int.Parse() method .
0
String concatenation is happening when u are printing the results with the + 1 which is why when u enter 10 printts out the 1 appended to it
instead add the one before print statement
- 2
SoloProg ,And separately the convert.tu command without inserting it into any method cannot be obtained?