Поставить таймер на одну минуту - C#
Формулировка задачи:
Листинг программы
- static void Main(string[] args)
- {
- Random rand1 = new Random();
- Random rand2 = new Random();
- int ans,num,num1,res;
- int k=0;
- while (k!=5) {
- k++;
- num = rand1.Next(1, 100);
- num1 = rand1.Next(1, 100);
- res = num + num1;
- Console.WriteLine(num + " + " + num1 + " = " + res);
- ans = int.Parse(Console.ReadLine());
- if (ans == res)
- {
- Console.WriteLine("true");
- }
- else if(ans!=res) Console.WriteLine("false");
- }
- }
Нужно в условии цикла поставить таймер на минуту
Решение задачи: «Поставить таймер на одну минуту»
textual
Листинг программы
- private delegate int Operation(int x, int y);
- private static void Main(string[] args)
- {
- var rand1 = new Random();
- int ans, num, num1, res, gen;
- DateTime end = DateTime.Now.AddMinutes(1);
- var op = new[]
- {
- new KeyValuePair<Operation, char>((x, y) => x + y, '+'),
- new KeyValuePair<Operation, char>((x, y) => x - y, '-'),
- new KeyValuePair<Operation, char>((x, y) => x * y, '*'),
- new KeyValuePair<Operation, char>((x, y) => x / y, '/'),
- };
- while (DateTime.Now < end)
- {
- num = rand1.Next(1, 100);
- num1 = rand1.Next(1, 100);
- int maxNum = Math.Max(num, num1);
- int minNum = Math.Min(num, num1);
- gen = rand1.Next(4);
- res = op[gen].Key(maxNum, minNum);
- Console.WriteLine("{0} {2} {1} = {3}", maxNum, minNum, op[gen].Value, res);
- ans = int.Parse(Console.ReadLine());
- Console.WriteLine(ans == res ? "true" : "false");
- Console.WriteLine("Осталось {0:ss} секунд", end - DateTime.Now);
- }
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д