Calculating The Tip And Total
Part of the Fundamentals section of Coddy's GDScript journey. Lesson 40 of 92.
Challenge
EasyNow calculate the tip and the total. Keep the code from the previous steps, and add after it:
- Calculate the tip and store it in
tip_amount, with this formula:(tip_percentage / 100) * bill_amount - Add the tip amount to the bill amount and store the result in
total_amount. - Print
total_amount.
For example, if the inputs are 64.3 and 9.0, the program prints:
Bill Split Calculator
70.087total_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
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