Menu
CoddyTech

전체 지출 보기

Coddy GDScript 여정의 기초 섹션에 포함된 레슨. 92개 중 86번째.

challenge icon

챌린지

쉬움

선택지 2를 처리하여 모든 지출을 표시하세요. 이전 단계에서 작성한 내용은 모두 그대로 유지하세요.

지출 배열이 비어 있으면 다음을 출력하세요:

No expenses recorded yet.

그렇지 않으면 Your expenses:을 출력한 다음 각 지출을 번호와 함께 1부터 시작하여 표시하세요. 23.1, 35.5, 99.99, 15.2 순서로 추가한 경우 출력은 다음과 같습니다:

Your expenses:
1. 23.1
2. 35.5
3. 99.99
4. 15.2

정수로 입력한 지출도 float으로 저장되므로 12는 12.0으로 표시됩니다.

직접 해보기

extends Node

func _ready():
	print("Welcome to the Daily Expense Tracker!")

	# 메뉴를 한 번 표시
	print("\nMenu:")
	print("1. Add a new expense")
	print("2. View all expenses")
	print("3. Calculate total and average expense")
	print("4. Clear all expenses")
	print("5. Exit")

	# 지출을 저장할 빈 배열
	var expenses: Array[float] = []

	while true:
		# 사용자의 선택을 입력받기
		var choice := OS.read_string_from_stdin()

		if choice == "1":
			# 새 지출 추가
			var amount := float(OS.read_string_from_stdin())
			expenses.append(amount)
			print("Expense added successfully!")
		elif choice == "5":
			# 프로그램 종료
			print("Exiting the Daily Expense Tracker. Goodbye!")
			break

기초의 모든 레슨

직접 연습해 보세요: 온라인 GDScript 컴파일러