Problems with c # console program

I need help understanding what might be wrong with this simple C # console program. I want to perform various arithmetic operations through classes. Here is the program.

static void Main(string[] args) { Console.Clear(); Arithmetic a1 = new Arithmetic(); Console.Write("\nEnter the value for first variable\n"); a1.obj1 = Console.Read(); Console.Write("\nEnter the value for the second variable\n"); a1.obj2 = Console.Read(); Console.WriteLine("Press any key to exit"); Console.ReadKey(); } 

Apparantley, the program builds and compiles ok, but at run time it takes the value of the first integer and does not take the value of the next integer, it writes the last line on the display (press any key to exit)

+4
source share
1 answer

Console.Read() reads a single character from standard input and returns its ASCII value.
If you press two keys, each call to Console.Read() will return one of them

You probably want ReadLine() , which reads a whole line of text (which you then want to parse into int ).

+6
source

Source: https://habr.com/ru/post/1490343/


All Articles