Не работает конструкция switch-case - C#
Формулировка задачи:
Здравствуйте. Изучаю С# вторую неделю и не понимаю почему у меня не работает switch-case в коде.Возможно это не switch-case, а что-то другое, но не работает именно один из кейсов (58 строка ).
Логика очень проста:
1)quit=false
2) Пишу в case() если пользователь ввел 'q' : quit=true;
3) в цикле Do-while. Пишу в конце программы while(!quit) то есть если я ввожу 'q' в консоль цикл не должен выполняться и программа должна завершаться. Увы но цикл идет дальше.
Скриншот прилагается!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DZ_s_16_
{
class Program
{
static void Main(string[] args)
{
int day = 0;
bool quit = false;
bool flag = false;
Console.WriteLine("");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Instruction");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("Write day of week 1 = Monday");
Console.WriteLine("Write day of week 2 = Tuesday");
Console.WriteLine("Write day of week 3 = Wednesday");
Console.WriteLine("Write day of week 4 = Thursday");
Console.WriteLine("Write day of week 5 = Friday");
Console.WriteLine("Write day of week 6 = Saturday");
Console.WriteLine("Write day of week 7 = Sunday");
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("If you wont to quit ,Please write 'q' and press Enter");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine();
do
{
try
{
Console.Write("If you read instruction, Enter day of week : ");
day = int.Parse(Console.ReadLine());
}
catch
{
flag = true;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("\aPlease,Read Instruction");
Console.ForegroundColor = ConsoleColor.White;
}
if (!flag)
{
switch (day)
{
case 1: Console.WriteLine("Monday (Go work)"); break;
case 2: Console.WriteLine("Tuesday (Go work)"); break;
case 3: Console.WriteLine("Wednesday (Go work)"); break;
case 4: Console.WriteLine("Thursday (Go work)"); break;
case 5: Console.WriteLine("Friday (Go work)"); break;
case 6: Console.WriteLine("Saturday (Easy)"); break;
case 7: Console.WriteLine("Sunday (Easy)"); break;
case 'q': quit = true; break;
default:
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("\aPlease,Read Instruction");
Console.ForegroundColor = ConsoleColor.White;
}
break;
}
}
flag = false;
}
while (!quit);
}
}
}Решение задачи: «Не работает конструкция switch-case»
textual
Листинг программы
case '1': Console.WriteLine("Monday (Go work)"); break;
case '2': Console.WriteLine("Tuesday (Go work)"); break;
case '3': Console.WriteLine("Wednesday (Go work)"); break;
case '4': Console.WriteLine("Thursday (Go work)"); break;
case '5': Console.WriteLine("Friday (Go work)"); break;
case '6': Console.WriteLine("Saturday (Easy)"); break;
case '7': Console.WriteLine("Sunday (Easy)"); break;
case 'q': quit = true; break;