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.


  • QA Engineer

    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:

    1. Console.Write("Enter size of the board "); - Conclusion
    2. User picks "123" and presses. Enter♪ but in the loop of the launch ♪
    3. deskSize = Console.Read(); - We're taking it from the 123 launcher, we're leaving the "n"
    4. Console.WriteLine("x = "); - Conclusion
    5. x = Console.Read(); - There's no suitable data in the intake buffet. X - 0
    6. Console.WriteLine("y = ");- Conclusion
    7. y = 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 :
    Replacement Console.Read()Convert.ToInt32( Console.ReadLine() )

    P.S: If you're wrong, correct it.


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2