commit 3814503bde982b3feda802bd91f2baff2fbcc8a0 Author: Greg Gauthier Date: Sat Aug 20 00:44:33 2022 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..3ad4a3a --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/variable_stuff.iml b/.idea/variable_stuff.iml new file mode 100644 index 0000000..c254557 --- /dev/null +++ b/.idea/variable_stuff.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..7ab460d --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "variable_stuff" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..0bd6f71 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "variable_stuff" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..fc782a4 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,90 @@ +use std::io; + +const THREE_HOURS_IN_SECONDS: u32 = 60 * 60 * 3; + +fn main() { + let mut x = 5; + println!("The value of x is: {x}"); + x = 6; + println!("The value of x is: {x}"); + + println!("{THREE_HOURS_IN_SECONDS}"); + + let z = 5; + + let z = z + 1; + + { + let z = z * 2; + println!("The value of z in the inner scope is: {z}"); + } + + println!("The value of z is: {z}"); + + let spaces = " "; + let spaces = spaces.len(); + println!("{spaces}"); + + let glert: u32 = "42".parse().expect("Not a number!"); + println!("{glert}"); + + let q = 2.76; // f64 + let r: f32 = 3.11; // f32 + let s = 4.0; + println!("{q}"); + println!("{r}"); + println!("{s}"); // why is this printing as if it were an integer? + + // addition + let sum = 5 + 10; + println!("SUM: {sum}"); + + // subtraction + let difference = 95.5 - 4.3; + println!("DIFF: {difference}"); + + // multiplication + let product = 4 * 30; + println!("PROD: {product}"); + + // division + let quotient = 56.7 / 32.2; + let floored = 2 / 3; // Results in 0 + println!("QUOT: {quotient}"); + println!("FLOOR: {floored}"); + + // remainder + let remainder = 43 % 5; + println!("MOD: {remainder}"); + + let tup = (500, 6.4, "cowherd"); + let (m, n, o) = tup; + println!("The value of M is: {m}"); + println!("The value of N is: {n}"); + println!("The value of O is: {o}"); + + let months = ["January", "February", "March", "April", "May", "June", "July", + "August", "September", "October", "November", "December"]; + for mn in months { + println!("{mn}"); + } + + let j = [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 = index + .trim() + .parse() + .expect("Index entered was not a number"); + + let element = j[index]; + + println!("The value of the element at index {index} is: {element}"); +} \ No newline at end of file