Splitting The Bill
Part of the Fundamentals section of Coddy's GDScript journey. Lesson 41 of 92.
Challenge
EasyAdd the splitting feature. Keep everything from the previous steps, and:
- Read a third input, the number of people splitting the bill, cast it to
intand store it innum_people. Read it right after the tip percentage. - Calculate
amount_per_personby dividingtotal_amountbynum_people. - After the line that prints
total_amount, printamount_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.0435Try 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
4Operators Part 1
Arithmetic OperatorsInteger DivisionModulo OperatorArithmetic ShortcutsRecap - Simple MathComparison Operators10Functions
Declare a FunctionArgumentsReturnReturn TypesRecap - Sigma FunctionRecap - Validation FunctionDefault Values5Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Ternary Operator8Bill Split Calculator
Welcome MessageGetting InputPractice on your own: Online GDScript compiler