namespace SwitchFor { class Program { static void Main(string[] args) { int i = 3; int j = 5; uint s = 0; char n; for (int a = 0; a < 5; a++ ) { Console.WriteLine("Π’Π²Π΅Π΄ΠΈΡ‚Π΅ ΠΌΠ΅Ρ‚ΠΊΡƒ 1, 2, 3, 4, 5"); n = (char)Console.Read(); switch (n) { case '1': { j = j - i; s = s + (uint)j; } break; case '2': { j = j + i * 3; s = s + (uint)j; } break; case '3': { j = j--; s = s + (uint)j; } break; case '4': { j = (i - 5) * 2; s = s + (uint)j; } break; case '5': { j = i + j + 1; s = s + (uint)j; } break; default: { s = s + 1; } break; } } Console.WriteLine("Π‘ΡƒΠΌΠΌΠ° Ρ€Π°Π²Π½Π° "+s); Console.ReadKey(); } } } 

This is such a simple program, however, for some reason it works for me incorrectly.

 Π’Ρ‹Π²ΠΎΠ΄ Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±Ρ‹Ρ‚ΡŒ Ρ‚Π°ΠΊΠΈΠΌ: Π’Π²Π΅Π΄ΠΈΡ‚Π΅ ΠΌΠ΅Ρ‚ΠΊΡƒ 1, 2, 3, 4, 5 1 Π’Π²Π΅Π΄ΠΈΡ‚Π΅ ΠΌΠ΅Ρ‚ΠΊΡƒ 1, 2, 3, 4, 5 2 Π’Π²Π΅Π΄ΠΈΡ‚Π΅ ΠΌΠ΅Ρ‚ΠΊΡƒ 1, 2, 3, 4, 5 3 Π’Π²Π΅Π΄ΠΈΡ‚Π΅ ΠΌΠ΅Ρ‚ΠΊΡƒ 1, 2, 3, 4, 5 4 Π’Π²Π΅Π΄ΠΈΡ‚Π΅ ΠΌΠ΅Ρ‚ΠΊΡƒ 1, 2, 3, 4, 5 5 Π‘ΡƒΠΌΠΌΠ° Ρ€Π°Π²Π½Π° (ΠΈ ΠΊΠ°ΠΊΠΎΠ΅-Ρ‚ΠΎ число, ΠΏΠΎΠ»ΡƒΡ‡Π΅Π½Π½ΠΎΠ΅ Π² Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚Π΅ этих пяти дСйствий). 
  • Why did you decide so?) - Gorets
  • If you mean the way I chose the tags, then this is random. You can choose them differently. But also in a different way also works incorrectly Try to make this program on c # and see what happens. - Svyatoslav
  • And what can be seen, i.e. what is wrong? How should a dialogue go? Try to print after entering n and make sure everything is fine. Perhaps the input line n should look something like n = Console.ReadLine()[0]; ? - alexlz
  • From your question it is not clear what should have been and what is really there. In any case, if the program is executed, then there is no compilation error. - Nicolas Chabanovsky ♦

2 answers 2

Replace, as you wrote above, the line:

 n = (char)Console.Read(); 

on:

 n = Console.ReadLine()[0]; 

and your cycle will work correctly.

Quote from MSDN :

Return control of the Read method is blocked until input characters are entered from the keyboard; the method returns control after the user presses the Enter key. In response to pressing the Enter key, a platform-dependent sequence of characters is added to the input, identifying the end of the line (for example, a carriage return is added to Windows). Subsequent calls to the Read method retrieve user input one character at a time. After retrieving the last character, the Read method again blocks the return of control and the cycle repeats.

    Yes, I incorrectly formulated. There is a conclusion, but instead of the necessary one (see above) it turns out like this:

     Π’Π²Π΅Π΄ΠΈΡ‚Π΅ ΠΌΠ΅Ρ‚ΠΊΡƒ 1, 2, 3, 4, 5 1 Π’Π²Π΅Π΄ΠΈΡ‚Π΅ ΠΌΠ΅Ρ‚ΠΊΡƒ 1, 2, 3, 4, 5 Π’Π²Π΅Π΄ΠΈΡ‚Π΅ ΠΌΠ΅Ρ‚ΠΊΡƒ 1, 2, 3, 4, 5 Π’Π²Π΅Π΄ΠΈΡ‚Π΅ ΠΌΠ΅Ρ‚ΠΊΡƒ 1, 2, 3, 4, 5 2 Π’Π²Π΅Π΄ΠΈΡ‚Π΅ ΠΌΠ΅Ρ‚ΠΊΡƒ 1, 2, 3, 4, 5 3 Π‘ΡƒΠΌΠΌΠ° Ρ€Π°Π²Π½Π° 16