C#/수업 내용

반복문 줄넘기 횟수 저장 후 출력하기

HSH12345 2023. 1. 3. 11:23
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Study02
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("줄넘기를 몇회 하시겠습니까?(1~5)");
            int repeatNum = Convert.ToInt32(Console.ReadLine());

            if (repeatNum > 0 && repeatNum <= 5)
            {
                for(int i = 0; i < repeatNum; i++)
                {
                    int jump = i + 1;
                    Console.WriteLine("줄넘기를 {0}회 하였습니다.", jump);

                    if (i + 1  == repeatNum)
                    {
                        Console.WriteLine("\n줄넘기를 총 {0}회 하였습니다..", repeatNum);
                    }
                }
            }
            else
            {
                Console.WriteLine("잘못된 수를 입력하였습니다.");
            }   
        }
    }
}