We can define functions to have parameters, which are special variables that are part of a function’s signature. - The book
In The Book about function parameter, there's sample code when i pass value to main and other function parameter for storing integer & variable names.
fn main() {
another_function(2000);
}
fn another_function(two_thousand: i32){
println!("My monthly income is {two_thousand}$");
}
Just curious about parameter () on the function. So is there's any example when we must use parameter rather than putting variable or anything on the body function.
Functions have parameters so that they can be told to do something different when they are called from different places or different times.
In a program this small, there is no need to have any functions but main(), so there is no need for parameters. In more complex programs, functions are absolutely essential — programs would be huge if you couldn't reuse code to do more than one job and build up complex programs out of small, separable parts.
Oh, you're asking why do we need functions with parameters. Right?
Is this your first programming language? If so, Rust is not a good choice. Rust is a relatively complex language, and the Rust book does not explain beginning concepts like function parameters.
As an aside, there have been other threads with some suggestions for those who are new to programming (along side lots of conversation about how suitable Rust is or isn't as a first language -- which there is no consensus on). For example, and another, and surely others if you search.