남영운 :: if else를 이용한 줄넘기 입력 실패시 되돌리기(19.09.20)

if else를 이용한 줄넘기 입력 실패시 되돌리기(19.09.20)

Console(콘솔)/실습 2019. 9. 20. 17:25
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
56
57
58
59
60
61
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Syntax04
{
    class Program
    {
        static void Main(string[] args)
        {
           c:
            Console.Write("줄넘기를 하려면 D 키를 입력 해주세요. ");
            ConsoleKeyInfo info = Console.ReadKey();
            Console.Clear();
            if (info.KeyChar == 'd')
            {
                Console.Write("몇회 줄넘기를 할건가요? ");
                int a = int.Parse(Console.ReadLine());
 
                for (int b=1;b<=a;b++)
                {
                    if (b % 2 == 1)
                    {
                        Console.Write("줄넘기를 ");
                        Console.ForegroundColor=ConsoleColor.Green;
                        Console.Write(b);
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.Write(" 회 했습니다.");
                        if (b % 3 == 0)
                        {
                            Console.WriteLine("(" + "\"야호!\"" + ")");
                        }
                        else
                        {
                            Console.WriteLine();
                        }
 
                    }
                    else if (b % 6 == 0)
                    {
                        Console.Write("줄넘기를 " + b + " 회 했습니다.");
                        Console.WriteLine("(" + "\"야호!\"" + ")");
                    }
                    else
                    {
                        Console.WriteLine("줄넘기를 " + b + " 회 했습니다.");
                    }
                }
            }
            else
            {
                Console.WriteLine("줄넘기를 하지 못했습니다.");
                Console.Clear();
                goto c;
            }
        }
    }
}
 
 
 

일단 되돌린겁니다.

위에 c:(세미콜론아님)  goto c;

: