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

7th Apr 2021, 2:04 PM
Alfréd Benko
Alfréd Benko - avatar
3 Respuestas
+ 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) ;
7th Apr 2021, 2:18 PM
Abhay
Abhay - avatar
+ 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
7th Apr 2021, 2:14 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Thanks very much ;)
7th Apr 2021, 2:20 PM
Alfréd Benko
Alfréd Benko - avatar