0
What is wrong with my code (NOOB)
I'm trying to write this code and it's not working. what's wrong? using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int x; int y; int z; Console.WriteLine("picl number!"); x=Console.ReadLine(); Console.WriteLine("pick nother!"); y=Console.ReadLine();
3 Answers
+ 2
Captain Fach... you must convert the value of user input to Convert.ToInt32.
The default value of user input (Console.ReadLine()) is in string. Just need to convert the string value in Int32 because the data type of the variable x and y is Int.
int x;
int y;
int z;
Console.WriteLine("picl number!");
x=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("pick nother!");
y=Convert.ToInt32(Console.ReadLine());
Nothing wrong with your code just need to convert the user input value. :) you are doing good. Keep Going. :)
0
I assume the missing braces are just typo's.
You are trying to assign a string returned by Console.ReadLine to an int. There is no implicit conversion for that, so you have to use something like Convert.ToInt32()
0
Always good to use Nullable.
public int? X { get; set; }
public int? Y { get; set; }
public int? Z { get; set; }
these statements wont be throwing an error when user just clicks on enter key .
x=Convert.ToInt32(Console.ReadLine());