0
where am I making mistake
I tried to make a simple code that asks the person in question for their name and age. then the console writes these variables https://code.sololearn.com/c92wZ2pKDn97/?ref=app
3 Réponses
+ 4
Console.ReadLine returns a string, so you need to convert age to int .
string name = Console.ReadLine();
int age=Convert.ToInt32(Console.ReadLine());
Console.WriteLine(quot;Name: {name}");
Console.WriteLine(quot;Age: {age}");
}
}
Other ways to convert a string to int or any other number,
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/types/how-to-convert-a-string-to-a-number
btw it is "WriteLine" not "Writeline" and you need to mention variable name and use "quot; for string formatting .
Otherwise mention the variable name like ,
Console.WriteLine("Name: {0}",name) ;
+ 2
Hello Alfréd Benko
Your problem is the integer input. Console.ReadLine() returns String.
Here you can find some possibilities how to deal with integer: https://stackoverflow.com/questions/24443827/reading-an-integer-from-user-input
+ 1
Thanks very much ;)