Compare commits

..

2 Commits

Author SHA1 Message Date
f28d70b9b8
Add new projects 2023-10-01 20:35:50 -04:00
e6bc4ef483
Rename old projects from my last attempt 2023-10-01 20:35:26 -04:00
8 changed files with 78 additions and 26 deletions

View File

@ -1,8 +1,11 @@
fn main() { fn main() {
let x = plus_one(5); print_labeled_measurement(37, 'h');
}
fn another_function(x: i32) {
println!("The value of x is: {x}"); println!("The value of x is: {x}");
} }
fn plus_one(x: i32) -> i32 {
x + 1 fn print_labeled_measurement(value: i32, unit_label: char) {
println!("The measurement is: {value}{unit_label}");
} }

7
old_functions/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "functions"
version = "0.1.0"

8
old_functions/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "functions"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@ -0,0 +1,8 @@
fn main() {
let x = plus_one(5);
println!("The value of x is: {x}");
}
fn plus_one(x: i32) -> i32 {
x + 1
}

7
old_variables/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "variables"
version = "0.1.0"

8
old_variables/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "variables"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

27
old_variables/src/main.rs Normal file
View File

@ -0,0 +1,27 @@
use std::io;
fn main() {
let a = [1, 2, 3, 4, 5];
println!("Please enter an array index.");
let mut index = String::new();
io::stdin()
.read_line(&mut index)
.expect("Failed to read line");
let index: usize = match {index.trim().parse()} {
Ok(x) => x,
Err(_) => {println!("expected an index, got \"{:}\". assuming 0", index.trim()); 0},
};
println!("got value {index}");
let element = a[index];
/* this is a
* multiline
* comment */
println!("The value of the element at index {index} is: {element}");
}

View File

@ -1,27 +1,11 @@
use std::io;
fn main() { fn main() {
let a = [1, 2, 3, 4, 5]; let x = 5;
let x = x + 1;
println!("Please enter an array index."); {
let x=x*2;
let mut index = String::new(); println!("The value of x in the inner scope is: {x}");
}
io::stdin()
.read_line(&mut index) println!("The value of x is: {x}");
.expect("Failed to read line");
let index: usize = match {index.trim().parse()} {
Ok(x) => x,
Err(_) => {println!("expected an index, got \"{:}\". assuming 0", index.trim()); 0},
};
println!("got value {index}");
let element = a[index];
/* this is a
* multiline
* comment */
println!("The value of the element at index {index} is: {element}");
} }