diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..e6615a6 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,4 @@ +[[package]] +name = "c2f" +version = "0.1.0" + diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..5234f94 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "c2f" +version = "0.1.0" +authors = ["Dakota "] + +[dependencies] diff --git a/src/Notes b/src/Notes new file mode 100644 index 0000000..5fce031 --- /dev/null +++ b/src/Notes @@ -0,0 +1,26 @@ + +// Formulas +// C to F +// C = (F-32) * (5/9) + +// F to C +// F = C * (9/5) + 32 + +fn main() { + let fahrenheit = c2f(0); + println!("C2F: {}", fahrenheit); + let celsius = f2c(0); + println!("F2C: {}", celsius); +} + +// Conavert Celsius to Fahrenheit +fn c2f(degree: i16) -> i16{ + let resualts = degree * (9/5) + 32; + resualts +} + +// Converts Fahrenheit to Celsius +fn f2c(degree: i16) -> i16{ + let resualts = (degree - 32) * (5/9); + resualts +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..f0d7195 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,101 @@ + +// Formulas +// C to F +// C = (F-32) * (5/9) + +// F to C +// F = C * (9/5) + 32 + +use std::env; +use std::process; + +fn main() { + + let in_arges: Vec = env::args().collect(); + + // Uncomment for debug purposes + //for i in 0..in_arges.len(){ + // println!("Arges[{}]: {}", i, in_arges[i]); + //} + + if in_arges.len() < 2 && in_arges[1] != "--help"{ + println!("Not enough arguments, run c2f --help"); + std::process::exit(0); + } else if in_arges.len() >= 5 { + println!("Too Many arguments, run c2f --help"); + std::process::exit(0); + } + + if in_arges[1] == "--help"{ + help(); + std::process::exit(0); + }else if in_arges[1] == "--c2f" { + let input = in_arges[2].parse::().unwrap(); + let results = c2f(input); + println!("C2F: {}", results); + }else if in_arges[1] == "--f2c" { + let input = in_arges[2].parse::().unwrap(); + let results = f2c(input); + println!("F2C: {}", results); + }else if in_arges[1] == "--f2ct"{ + let arg1 = in_arges[2].parse::().unwrap(); + let arg2 = in_arges[3].parse::().unwrap(); + range_table("f".to_string(), arg1, arg2); + }else if in_arges[1] == "--c2ft"{ + let arg1 = in_arges[2].parse::().unwrap(); + let arg2 = in_arges[3].parse::().unwrap(); + range_table("c".to_string(), arg1, arg2); + } else if in_arges[1] == "--f2b"{ + freezing_to_boiling(); + } +} + +// Conavert Celsius to Fahrenheit +fn c2f(degree: f32) -> f32{ + let resualts = degree * (1.8) + 32.0; + resualts +} + +// Converts Fahrenheit to Celsius +fn f2c(degree: f32) -> f32{ + let resualts = (degree - 32.0) * (0.555555556); + resualts +} + +fn help(){ + println!("--help Prints this menu"); + println!("--c2f , Converts a Celsius degree to Fahrenheit"); + println!("--f2c , Converts a Fahrenheit degree to Celsius"); + println!("--f2ct , Prints a table converting between a range of Fahrenheit to Celsius"); + println!("--c2ft , Prints a table converting between a range of Celsius to Fahrenheit"); + println!("--f2b Prints the table from freezing ot boiling, C to F"); + println!("--ver Prints the program version"); +} + +// tempeture c or f as options +fn range_table(tempeture_type: String, staring_range: i32, ending_range: i32){ + + println!("Staring temp: {},| Ending Temp {}", &staring_range, ending_range); + println!("-------------------------------------"); + + if tempeture_type == "c"{ + + for i in staring_range..ending_range + 1 { + let temp_i = i as f32; + let resualt = c2f(temp_i); + println!("F: {} | C: {}", i , resualt); + } + }else if tempeture_type == "f"{ + for i in staring_range..ending_range + 1{ + let temp_i = i as f32; + let resualt = f2c(temp_i); + println!("C: {} | F: {}", i , resualt); + } + }else{ + println!("Not a valid input"); + } +} + +fn freezing_to_boiling(){ + range_table("c".to_string(), 0, 100); +} \ No newline at end of file