09.20 줄넘기

C#/실습 2019. 9. 20. 17:08

예제:

d키 입력여부

D키 입력시:

다른키 입력시:

다른키 입력시

D키를 입력 할때까지 저 문구가 나온다.

줄넘기 횟수 입력시:

홀수 숫자는 초록색으로 나타냈고

줄넘기 횟수가 3의 배수인 경우에는 뒤에 ("야호!")를 붙였다.

코드:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace stntax03
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            { 
            Console.Write("줄넘기를 하려면 D 키를 입력 해주세요.");
            ConsoleKeyInfo keyinfo2 = Console.ReadKey();
            bool input = keyinfo2.KeyChar == 'd';
                //string a = keyinfo2.KeyChar.ToString(); //ConsoleKeyInfo 형태를 string 형태로 바꾸기
                Console.Clear();
                if (input)
                {
                    Console.Write("몇회 줄넘기를 할건가요?");
                    string strcount = Console.ReadLine();
                    int count = Convert.ToInt32(strcount);
                    for (int i = 1; i <= count; i++)
                    {
                        if (i % 2 == 0)
                        {
                            Console.Write($"줄넘기를 {i}회 했습니다.");
                        }
                        else
                        {
                            Console.Write("줄넘기를 ");
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.Write(i);
                            Console.ResetColor();
                            Console.Write("회 했습니다.");
                        }
                        if (i % 3 == 0)
                        {
                            Console.Write("(\"야호!\")");
                        }
                        Console.WriteLine();
                    }
                 break;
                }
                else
                {
                    Console.WriteLine("줄넘기를 하지 못했습니다");
                }
            }
        }
    }
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

 

 

: