Add units to the output

This commit is contained in:
Carol (Nichols || Goulding)
2016-09-23 15:32:02 -04:00
parent cf9e0a8ae7
commit bdcddf29a7
+13 -4
View File
@@ -79,7 +79,10 @@ fn main() {
let length1 = 50;
let width1 = 30;
println!("The area of the rectangle is {}", area(length1, width1));
println!(
"The area of the rectangle is {} square pixels.",
area(length1, width1)
);
}
fn area(length: u32, width: u32) -> u32 {
@@ -90,7 +93,7 @@ fn area(length: u32, width: u32) -> u32 {
Let's try running this program with `cargo run`:
```bash
The area of the rectangle is 1500
The area of the rectangle is 1500 square pixels.
```
### Refactoring with Tuples
@@ -120,7 +123,10 @@ Filename: src/main.rs
fn main() {
let rect1 = (50, 30);
println!("The area of the rectangle is {}", area(rect1));
println!(
"The area of the rectangle is {} square pixels.",
area(rect1)
);
}
fn area(dimensions: (u32, u32)) -> u32 {
@@ -161,7 +167,10 @@ struct Rectangle {
fn main() {
let rect1 = Rectangle { length: 50, width: 30 };
println!("The area of the rectangle is {}", area(&rect1));
println!(
"The area of the rectangle is {} square pixels.",
area(&rect1)
);
}
fn area(rectangle: &Rectangle) -> u32 {