where am I making mistake | Sololearn: Learn to code for FREE!

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

4/7/2021 2:04:43 PM

Alfréd Benko

3 Answers

New Answer

+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($"Name: {name}"); Console.WriteLine($"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 "$" 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 ;)