JAVA_편의점 거스름돈 계산기

박예린·2022년 12월 20일
0

Java

목록 보기
5/23

public static void main(String[] args) {
		/*
		 * 편의점 프로그램
		 * 지불금액 : 3,210원
		 * 본인금액 : 10,000원
		 * 
		 * 거스름돈 -> ?
		 * 
		 * 5000원 ?장
		 * 1000원 ?장
		 * 500원 ?장
		 * 100원 ?장
		 * 50원 ?장
		 * 10원 ?장
		 */
		
		Scanner sc = new Scanner(System.in);
		
		int mymoney, pay, result;
		int bigfive=0;
		int bigten=0;
		int midfive=0;
		int midten=0;
		int smallfive=0;
		int smallten=0;
		
		System.out.println("본인 금액을 입력하시오.");
		mymoney = sc.nextInt();
		System.out.println("지불할 금액을 입력하시오.");
		pay = sc.nextInt();
		
		result = mymoney - pay;
		
		bigfive = result / 5000;
		bigten = result % 5000 / 1000;
		midfive = result % 5000 % 1000 / 500;
		midten = result % 5000 % 1000 % 500 / 100;
		smallfive = result % 5000 % 1000 % 500 % 100 / 50;
		smallten = result % 5000 % 1000 % 500 % 100 % 50 / 10;
		
		System.out.println("5000원 = " + bigfive+"장");
		System.out.println("1000원 = " + bigten+"장");
		System.out.println("500원 = " + midfive+"장");
		System.out.println("100원 = " + midten+"장");
		System.out.println("50원 = " + smallfive+"장");
		System.out.println("10원 = " + smallten+"장");
		
	}

}
profile
개발자를 꿈꾸는 귀여운 나

0개의 댓글