Menu
CoddyTech

Splitting The Bill

Part of the Fundamentals section of Coddy's GDScript journey. Lesson 41 of 92.

challenge icon

Challenge

Easy

Add the splitting feature. Keep everything from the previous steps, and:

  1. Read a third input, the number of people splitting the bill, cast it to int and store it in num_people. Read it right after the tip percentage.
  2. Calculate amount_per_person by dividing total_amount by num_people.
  3. After the line that prints total_amount, print amount_per_person.

Print only the numbers, without labels. For example, for the inputs 64.3, 9.0 and 2, the program prints:

Bill Split Calculator
70.087
35.0435

Try it yourself

extends Node

func _ready():
	print("Bill Split Calculator")

	var bill_amount := float(OS.read_string_from_stdin())
	var tip_percentage := float(OS.read_string_from_stdin())

	var tip_amount := (tip_percentage / 100) * bill_amount
	var total_amount := bill_amount + tip_amount

	print(total_amount)

All lessons in Fundamentals

Practice on your own: Online GDScript compiler