+ 2

How to use multiple Console.ReadLine()

What if you ask for to different inputs. One as string and one as int. Like string yourName = Console.ReadLine(); Console.WriteLine("Your name is {0}",yourName ); int yourAge = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Your age is {0}",yourAge ); I can only input the fhirst one but its not asking for the other. And is it possible to make a question for what your asking? Like: please fill in your name.

30th Jul 2016, 11:49 PM
Lars Erkeland
Lars Erkeland - avatar
5 Answers
+ 2
When you are entering multiple inputs into this mobile app you must enter all inputs you expect to use at the same time...just separate them by different lines...for example: int x = Console.ReadLine(); int y = Console.ReadLine(); Console.WriteLine(x); Console.WriteLine(y); You would have to enter both x and y at the same time just putting the y value on a new line like this: 3 6 srry long explanation, but dont worry on an actual computer you will be prompted however many times you ask for user input
2nd Aug 2016, 4:25 AM
Dakota Lewis
Dakota Lewis - avatar
+ 1
Maybe try writing your code like this string yourName = Console.ReadLine (); Console.WriteLine ("Your name is, " + yourName); int yourAge = Convert.ToInt32 (Console.ReadLine ()); Console.WriteLine ("Your age is, " + yourAge); Console.ReadKey (); I use XamarinStudio so I don't know if it will work in visual studio.
31st Jul 2016, 5:49 PM
Tiwonge M'hango
Tiwonge M'hango - avatar
+ 1
i think after you saw tge output of first Console.Writelin, you should press Enter another time for console to go to the next line.or to be sure you can write it like this: string yourName = Console.ReadLine(); Console.WriteLine("Your name is {0}",yourName ); Console.ReadLine (); int yourAge = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Your age is {0}",yourAge ); ____________ or you can just use Parse when youre gonna give the console the value for int yourAge: int yourAge=int.parse. (Console.ReadLine ());
12th Aug 2016, 9:15 PM
Amir
0
it says when you go to input something "split multiple inputs into separate lines"
12th Aug 2016, 11:04 PM
Dakota Lewis
Dakota Lewis - avatar
- 2
The real program you can insert as many as much as possible Console.ReadLine() and ask the user to input data in it, but in this application, it can't command more than one Console.ReadLine() because its connected and do with connection, but not in internal
31st Jul 2016, 4:19 AM
Elvin Tech
Elvin Tech - avatar