Functions and Errors
Functions
Inputs and Return
A function names a calculation. The final expression with no semicolon is the return value.
Program
Play the program to send a subtotal through a function and back.
functions.rs
fn main() {
let subtotal = 25;
let total = add_tax(subtotal);
println!("{total}");
}
fn add_tax(price: i32) -> i32 {
price + price / 10
}
fn
`fn add_tax(price: i32) -> i32` declares inputs and output.
argument
`add_tax(subtotal)` passes the current subtotal.
implicit return
The last expression (no `;`) is returned.