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 let width = 20; 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 let width:u32=14; let height:u32=20; prints_values(width,height); let mult:u32= height*width; mult // 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 = 10; let height: u32 = 10; // 2. Declare a variable named height // 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 = 1; 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 { // 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 = 23; 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 { let width:u32 = 2; let height: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 // 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 = 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 { let width: u32 = 10; let height: u32 = 20; prints_values(width, height); return width * height}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 let width: u32 = 42; // 2. Declare a variable named height let height: u32 = 501; // 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 mut width=50; // 2. Declare a variable named height let mut height=60; // 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 = 5; 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 = 2; let height:u32 = 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 = 5; let height: u32 = 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 // 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 = 5; 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: u32 = 6; let height: u32 = 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 // 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 prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}pub fn calculate_area() -> u32 { let width = 3; let height = 3; prints_values(width, height); width * 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 = 42; // 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 = 1; let height: u32 = 1; 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); 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 = 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 let width:u32 = 52; // 2. Declare a variable named height let height:u32 = 52; // 3. Run the `prints_values` function with the width and height variables prints_values(width,height); // 4. Return the multiplication of width and height let total:u32= width*height; total}// 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=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 // 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 = 4; prints_values(3, 4); 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 = 24; 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 = 3; 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 { let width = 8; let height = 10; prints_values(width, height); 8 * 10}// 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 = 13; 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 = 10; 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 { 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 { let width: u32 = 3; let height: u32 =4 ; 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 = 24; // 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 = 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 // 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 = 4; 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 { let width: u32 = 31; let height: u32 = 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 mut width: u32 = 2; // 2. Declare a variable named height let mut 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 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 = 2; 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 = 1; 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 = 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 :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 = 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 = 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 =10; let height=20; prints_values(width,height); 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 = 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 let width = 30; let height = 30; prints_values(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 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 = 30; let height = 30; prints_values(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 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 = 100; // 2. Declare a variable named height let height = 100; // 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 = 25; let height: u32 = 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 // 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 = 24; 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);}