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 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 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 { // 1. Declare a variable named width let width = 3; // 2. Declare a variable named height let height = 2; // 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 { // 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 let width = 24u32; // 2. Declare a variable named height let height = 18u32; // 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 = 12; let height = 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 let width: u32 = 4; // 2. Declare a variable named height let height: u32 = 4; // 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 = 5; let height: u32 = 2; 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: u32 = 22; // 2. Declare a variable named height let height: u32 = 44; // 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 = 8; 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 = 10; let height = 20; 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 = 42; let height : u32 = 42; 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 = 32; 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 // 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 = 32; 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 // 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 = 1; let height: u32 = 2; 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 = 4; 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 = 4; // 2. Declare a variable named height let height = 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 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 = 32; let height : u32 = 32; 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 = 4; // 2. Declare a variable named height let height = 4; // 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 = 5; // 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 let width = 10; let height = 10; prints_values(width, height); width * height // 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 = 20; 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 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}// 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 = 2; 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 let w = 12; // 2. Declare a variable named height let h = 5; // 3. Run the `prints_values` function with the width and height variables prints_values(w,h); // 4. Return the multiplication of width and height return w * h;}// 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 = 1; let height = 1; 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 = 20; let height = 15; prints_values(width, height); let area:u32 = width*height; println!("The area of the rectangle is: {}", area); 1}// 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 // 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 = 10u32; let height = 10u32; 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) = (1_u32, 2_u32); 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 = 3; let height: u32 = 7; prints_values(width, height); width * height // 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 = 5; // 2. Declare a variable named height let height = 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 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 let width: u32 = 10; let height: u32 = 20; prints_values(width, height); width*height // 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 { let height :u32 = 10; let width : u32 =2; 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 // Declare width and height as immutable variables // Calculate the area of the rectangle // Return the calculated area let width = 10; let height = 5; prints_values(width, height); let area = width * height; area}pub 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 = 26; 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 = 20; 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 = 5; let height = 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: u32 = 10; let height: u32 = 15; 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 = 30; // 2. Declare a variable named height let height = 25; // 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 w = 2; let h = 5; prints_values(w, h); w * h}// 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); 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 = 20; 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 = 69; let height = 420; 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 = 19; let height = 10; 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: u32 = 12; // 2. Declare a variable named height let height: u32 = 32; // 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 = 2; let height = 2; 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 = 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 = 10; let area = width * height; prints_values(width, height); 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 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);}