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 = 15; let height = 15; prints_values(width,height); let area = &width * &height; return area 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 { 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 height: u32 = 10; let width: u32 = 10; prints_values(width, height); 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 = 1; // 2. Declare a variable named height let height = 1; // 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 = 45; // 2. Declare a variable named height let height: u32 = 50; // 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 = 10; // 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 let width: u32 = 24; // 2. Declare a variable named height let height: u32 = 45; // 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 = 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: u32 = 45; // 2. Declare a variable named height let height: u32 = 50; // 3. Run the `prints_values` function with the width and height variables prints_values(width, height); // 4. Return the multiplication of width and height 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 // 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 = 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 mut width: u32 = 8; // 2. Declare a variable named height let mut 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 { // TODO: Implement the function here // 1. Declare a variable named width let mut width: u32 = 8; // 2. Declare a variable named height let mut 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: u32 = 2; // 2. Declare a variable named height let height: u32 = 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 { // 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 = 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: u32 = 5; 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 = 1 ; 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 w = 4; let h = 5; prints_values(4,5); 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 = 10; let height = 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 = 10; 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 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 = 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 = 3; // 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 = 3; 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 { let width = 1; let height = 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 // 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 = 8; 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; 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 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); 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 = 42; // 2. Declare a variable named height let height: u32 = 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 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 = 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 let width: u32 = 1; // 2. Declare a variable named height let height: u32 = 1; // 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 = 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 { let width : u32 = 20; let height : u32 = 40; prints_values(width, height); 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 // 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 = 32; let width : u32 = 5; prints_values(height, width); return 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 // 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 { let width = 32; let height = 5; 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 = 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 = 40; let height: u32 = 30; 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 = 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 // 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; let result:u32 = width*height; prints_values(width, height); result}// 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: u32 = 5; let height: u32 = 8; 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 = 8; let height: u32 = 8; 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 = 20; // 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 // 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 = 1; 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 = 10; let height = 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 = 10_u32; let height = 5_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); }