09.20 줄넘기
C#/실습 2019. 9. 20. 17:08예제:

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;
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.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
|
'C# > 실습' 카테고리의 다른 글
09.24 최대공약수 구하기 (0) | 2019.09.24 |
---|---|
09.23 상점 구매하기 및 판매하기 (0) | 2019.09.23 |
09.20 for문을 이용한 던전게임 (0) | 2019.09.20 |
09.20 과일입력, 숫자입력, 문자열에 따옴표입력 (0) | 2019.09.20 |
구구단 (convert를 이용한 string형식을 int 형식으로 변환, tryparse를 이용한 문자와 숫자 구분) (0) | 2019.09.19 |