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.
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:
width
and height
.prints_values
function to display the values of the width
and height
.width
and height
.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_values
or using expressions inline), we recommend you practice declaring variables using thelet
keyword.
let
keyword to declare variables in Rust.prints_values
function is invoked with the correct arguments.width
and height
.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 let width: u32 = 3; let height: u32 = 5; prints_values(width, height); return width*height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width = 10 ; let height = 15; prints_values(width,height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width = 33; let height = 44; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width = 33; let height = 44; prints_values(width, height); 33 * 44}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width = 5; let height = 3; prints_values(width, height); return width * height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width let width = 10; // 2. Declare a variable named height let height = 10; // 3. Run the `prints_values` function with the width and height variables prints_values(width, height); // 4. Return the multiplication of width and height return width * height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width let width: u32 = 10; // 2. Declare a variable named height let height: u32 = 5; // 3. Run the `prints_values` function with the width and height variables prints_values(width, height); // 4. Return the multiplication of width and height width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width = 10; let height = 15; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width let width = 30; // 2. Declare a variable named height let height = 10; // 3. Run the `prints_values` function with the width and height variables prints_values(width, height); // 4. Return the multiplication of width and height width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width: u32 = 10; let height: u32 = 15; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width: u32 = 300; let height: u32 = 200; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width let width = 10; // 2. Declare a variable named height let height = 20; // 3. Run the `prints_values` function with the width and height variables prints_values(width, height); // 4. Return the multiplication of width and height width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width = 5; let height = 5; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here let width: u32 = 10; let height: u32 = 5; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { let width: u32 = 1; let height: u32 = 8; prints_values(width, height); return width * height // 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);}
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 let width: u32 = 10; let height: u32 = 20; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width: u32 = 5; let height: u32 = 9; prints_values(width, height); return width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width : u32 = 10; let height : u32 = 10; prints_values(width,height) }// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32)->u32 { println!("The width is: {}", width); println!("The height is: {}", height); width * height }
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width let width: u32 = 10; // 2. Declare a variable named height let height: u32 = 10; // 3. Run the `prints_values` function with the width and height variables prints_values(width, height); // 4. Return the multiplication of width and height return width * height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width = 3; let height = 4; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width = 3; let height = 4; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width = 3; let height = 4; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width: u32 = 10; let height: u32 = 5; prints_values(width, height); let area = width * height; return area;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width = 10; let height = 10; prints_values(width, height); return width * height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width = 5; let height = 4; prints_values(width,height); width*height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width = 10; let height = 10; prints_values(width, height); return width * height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width = 2; let height = 6; prints_values( width, height); width * height }// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width let width = 23; // 2. Declare a variable named height let height = 23; // 3. Run the `prints_values` function with the width and height variables prints_values(width,height); // 4. Return the multiplication of width and height width*height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width let width: u32 = 2; // 2. Declare a variable named height let height: u32 = 3; // 3. Run the `prints_values` function with the width and height variables prints_values(width, height); // 4. Return the multiplication of width and height width* height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width : u32 = 10; let height : u32 = 10; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width: u32 = 10; let height: u32 = 20; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width: u32 = 2; let height: u32 = 3; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width: u32 = 2; let height: u32 = 3; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width = 10; let height = 10; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width let width : u32 = 10 ; // 2. Declare a variable named height let height : u32 = 20 ; // 3. Run the `prints_values` function with the width and height variables prints_values( width , height) ; // 4. Return the multiplication of width and height (width * height) as u32 }// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width = 12; let height = 50; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width let width = 1920; // 2. Declare a variable named height let height = 1080; // 3. Run the `prints_values` function with the width and height variables prints_values(width, height); // 4. Return the multiplication of width and height return width * height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width let width = 2; // 2. Declare a variable named height let height = 3; // 3. Run the `prints_values` function with the width and height variables prints_values(width, height); // 4. Return the multiplication of width and height return width*height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width: u32 = 5; let height: u32 = 10; prints_values(width, height); return width * height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { let width = 4; let height = 3; prints_values(width, height); return width * height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width: u32 = 12; let height: u32 = 13; prints_values(width, height); return width*height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width = 10; let height = 15; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let height: u32 = 5; let width: u32 = 10; prints_values(height, width); height * width}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width let width: u32 = 10; // 2. Declare a variable named height let height: u32 = 15; // 3. Run the `prints_values` function with the width and height variables prints_values(width, height); // 4. Return the multiplication of width and height return width * height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width: u32 = 50; let height: u32 = 25; prints_values(width, height); return width * height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { let width: u32 = 10; let height: u32 = 20; prints_values(width, height); return width*height // 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);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width let width = 3; // 2. Declare a variable named height let height = 6; // 3. Run the `prints_values` function with the width and height variables prints_values(width, height); // 4. Return the multiplication of width and height width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { let (width, height) = (10, 10); prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let (width, height): (u32, u32) = (5, 10); prints_values(width, height); &width * &height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
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 let width : u32 = 5; let height : u32 = 7; prints_values(width,height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}