은행 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;
}
}
}
}
'IT > C#' 카테고리의 다른 글
C# (팩토리얼 재귀함수) (0) | 2021.05.13 |
---|---|
C# (객체지향_자동차 클래스 설계) (0) | 2021.05.06 |
C# (사용자가 랜덤 숫자를 맞추는 프로그램) (0) | 2021.05.06 |
C# (팩토리얼 구하기) (0) | 2021.05.06 |
C# (전역변수와 지역변수 차이) (0) | 2021.05.06 |