0
The code below ends to the error: "cannot implicitly convert "string" to "int". I can't get the logical point.
int a = 2; int b = 3; int c = 2; int x = (a + b) * c; Console.WriteLine("if x = (a + b) * c then what is 'x' if (a = 2, b = 3, c = 2)?"); int z; z = Console.ReadLine(); Console.WriteLine(z); if (z == x); { Console.WriteLine("the result is true"); }
1 Resposta
+ 1
Console.ReadLine() returns a string, you need to convert the string input to `int` by passing the input string as argument to Convert.ToInt32 method. If you don't do this, an attempt to compare <z> to <x> will fail because the two came from different class.
z = Convert.ToInt32(Console.ReadLine());