Menu
CoddyTech

Calculating The Tip And Total

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

challenge icon

Challenge

Easy

Now calculate the tip and the total. Keep the code from the previous steps, and add after it:

  1. Calculate the tip and store it in tip_amount, with this formula: (tip_percentage / 100) * bill_amount
  2. Add the tip amount to the bill amount and store the result in total_amount.
  3. Print total_amount.

For example, if the inputs are 64.3 and 9.0, the program prints:

Bill Split Calculator
70.087

total_amount is a float, so a whole total prints with a decimal point: 1150.0.

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())

All lessons in Fundamentals

Practice on your own: Online GDScript compiler