first_rust_repo/src/main.rs
2022-03-15 12:28:58 -05:00

86 lines
2 KiB
Rust

use std::io;
fn main() {
let mut wack = String::new();
f_to_c();
println!("Do you want to hear the singing? (y/n): ");
io::stdin()
.read_line(&mut wack)
.expect("ay yo that ain't it chief");
let choice: &str = wack.trim();
let mut done = false;
while done == false{
if choice == "y" || choice == "n"{
if choice == "y"{
done = true;
sing_goddamn_it();
}
else{
done = true;
}
}
else{
println!("man try again...or I'll slap your balls");
}
}
println!("{}",fibbonacci(-10));
}
fn f_to_c() {
let mut s = String::new();
println!("Type a float to be a fahrenheit: ");
io::stdin()
.read_line(&mut s)
.expect("Failed to read number, or number was formatted as an integer. Try putting a .0 at the end of the number...");
let x: f32 = s.trim().parse().unwrap();
let y = (x - 32.0)*(5.0/9.0);
println!("Fahrenheit: {} to Celsius: {}",x, y);
}
fn sing_goddamn_it() {
let sents = ["a partridge in a pear tree", "2 turtle-doves", "3 French hens", "4 calling birds", "5 golden rings", "6 geese a-laying",
"7 swans a-swimming", "8 maids a-milking", "9 ladies dancing", "10 lords a-leaping", "11 pipers piping", "12 drummers drumming"];
let mut days = 1;
for _number in 1..13{
println!("On the {} day of christmas, my true love sent to me", days);
for number2 in (0..0+days).rev(){
println!("{}", sents[number2]);
}
days += 1;
}
}
fn fibbonacci(n: i32) -> i32{
if n < 0
{
panic!("{} is a negative number, mucho no bueno...", n);
}else if n == 0{
panic!("equals zero, error");
}else if n == 1{
return 1;
}
let mut sum = 0;
let mut temp = 0;
let mut temp2 = 1;
for _i in 1..n {
sum = temp + temp2;
temp = temp2;
temp2 = sum;
}
sum
}