본문 바로가기
IT/C#

C# (은행 ATM 기기 프로그램)

by hjshims 2021. 5. 6.

은행 ATM 기기 프로그램

각 케이스별로 은행 프로그램이 동작해야 하기 때문에,

switch문을 사용하는 것이 조건문 구현할 때 더 깔끔한 코드가 될 수 있다.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RoadBook.CsharpBasic.Chapter01.f0506
{
    class test3
    {
        public void Run()
        {
            int money =0;
            Console.WriteLine("*******안녕하세요 Road Bank입니다.********");
            Console.WriteLine("1: 잔액조회");
            Console.WriteLine("2: 입금");
            Console.WriteLine("3: 출금");
            Console.WriteLine("0: 종료");
            Console.WriteLine("******************************************");

            while (true)
            {
                Console.Write("사용자: ");
                int user = Convert.ToInt32(Console.ReadLine());

                switch (user)
                {
                    case 1:
                        Console.WriteLine("잔액은 '"+money+"'원입니다. ");
                        continue;
                    case 2:
                        Console.WriteLine("입금할 금액을 입력하세요.");
                        int ib = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("입금되었습니다.");
                        money += ib;
                        continue;
                    case 3:
                        Console.WriteLine("출금할 금액을 입력하세요.");
                        int chul = Convert.ToInt32(Console.ReadLine());
                        money -= chul;
                        Console.WriteLine("출금되었습니다.");
                        continue;
                    case 0:
                        Console.WriteLine("감사합니다.");
                        break;
                }
                break;
            }
        }
    }
}

 

 

<출력결과>