input c# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

input c#

static void Main(string[] args) { String name; int age; double grade; Console.WriteLine("what is your name"); name = Console.ReadLine(); Console.WriteLine("may name is {0}",name); Console.WriteLine("how old are you"); age = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Im {1}", age); Console.WriteLine("my grade"); grade = Convert.ToDouble(Console.ReadLine()); Console.WriteLine("my grade {2}", grade); } ((( why double variable not appear ?? and other two variable are appeare((

14th Jul 2019, 8:03 PM
Sanaa Hareb
Sanaa Hareb - avatar
5 Answers
0
hi sanaa Hareb whats the output of that code....
14th Jul 2019, 8:08 PM
Mohammad Yahya Azhar
Mohammad Yahya Azhar - avatar
0
the output : what is your name Ali my name is Ali how old are you 28 but for double variable writen unhandle exception
14th Jul 2019, 8:26 PM
Sanaa Hareb
Sanaa Hareb - avatar
0
hi Sanaa Hareb here a fixed version of your code. the exception in your code was caused by age and grade lines... https://code.sololearn.com/cFv3QsSjyUJ9/?ref=app Console.WriteLine(“my grade {2}”, grade); this is because if you want to print grade to the screen it needs to be zero and putting it as 2 prints null to the screen and causes an error
14th Jul 2019, 8:35 PM
Ollie Q
Ollie Q - avatar
0
Do you know for what use is {number}? {0} means that it will take first variable that appears after comma in console.writeline {1} means that it will take second variable that appears after comma in console.writeline {2} means that it will take third variable that appears after comma in console.writeline ... Console.Writeline("I'm printing {0}{1}{2}", first,second,third); If you have obe parameter in cw, you don't need that, only if you want to print in another order then use it. 👌👌👌
14th Jul 2019, 10:29 PM
Dejan Francuz🥇
Dejan Francuz🥇 - avatar
- 1
those {n} indicates the function to replace it with the n+2 parameters. assuming the first parameter (the string) is 1. since syntax is {2} (the 4th parameter) and {1} (the 3rd parameter) but theres only 2 parameters. the function will try to find the value that doesnt exist.
14th Jul 2019, 8:44 PM
Taste
Taste - avatar