In this challenge, you will implement a function calculate_area that computes the area of a rectangle using a given width and height. The purpose of this exercise is to practice variable declaration.
Your Task
You are provided with a helper function prints_values that takes two parameters, width and height, and prints their values. Your task is to call this helper function inside calculate_area and ensure that the printed values are correct.
The calculate_area function should:
- Declare variables for
widthandheight. - Use the
prints_valuesfunction to display the values of thewidthandheight. - Return the calculated area of the rectangle by multiplying
widthandheight.
Do not modify the prints_values function.
Note: While it is possible to solve the challenge and pass the tests without explicitly declaring variables (e.g., by directly passing values to
prints_valuesor using expressions inline), we recommend you practice declaring variables using theletkeyword.
Hints
<details> <summary>Click here to reveal hints</summary>- Use the
letkeyword to declare variables in Rust. - Ensure the
prints_valuesfunction is invoked with the correct arguments. - The returned area should be the result of multiplying the
widthandheight.
pub fn calculate_area() -> u32 {// TODO: Implement the function here// 1. Declare a variable named width// 2. Declare a variable named height// 3. Run the `prints_values` function with the width and height variables// 4. Return the multiplication of width and height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) {println!("The width is: {}", width);println!("The height is: {}", height);}