Why is the program asking for two numbers?
-
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace HourseNask { class Program { static void Main(string[] args) { int x, y, deskSize; Console.Write("Enter size of the board "); deskSize = Console.Read(); Console.WriteLine("x = "); x = Console.Read(); Console.WriteLine("y = "); y = Console.Read(); } } }
Here's the C# code. Some deskSize counts, then it just goes to the console.
x=
y=
and the programme is complete. I mean, x and y are not counted, although they are also described.
-
Function
Console.Read()
picks up the maximum possible bulbs of suitable symbols from the buffalo of the insertion of the pre-marked new line-- \n, which it does not remove )So your program works as follows:
Console.Write("Enter size of the board ");
- Conclusion- User picks "123" and presses.
Enter
♪ but in the loop of the launch ♪ deskSize = Console.Read();
- We're taking it from the 123 launcher, we're leaving the "n"Console.WriteLine("x = ");
- Conclusionx = Console.Read();
- There's no suitable data in the intake buffet.X
- 0Console.WriteLine("y = ");
- Conclusiony = Console.Read();
- There's no suitable data in the intake buffet.Y
- 0
I mean, the problem is, there's still a new row symbol in the inject.
That's what I said. /users/3159/spectre :
ReplacementConsole.Read()
♪Convert.ToInt32( Console.ReadLine() )
P.S: If you're wrong, correct it.