A small program that takes a word (String) as input and translates it into Pig Latin
| use std::io; | |
| fn main() { | |
| let mut input = String::new(); | |
| loop { | |
| io::stdin().read_line(&mut input) | |
| .expect("Failed to read line"); | |
| input = input.trim().to_string(); | |
| piglatinize(&mut input); | |
| println!("{}", input); | |
| input.clear(); | |
| } | |
| } | |
| fn piglatinize(s: &mut String) { | |
| let initial_letter = s.remove(0); | |
| if !is_vowel(initial_letter) { | |
| s.push(initial_letter); | |
| s.push_str("-ay"); | |
| } else { | |
| s.push_str("-hay"); | |
| } | |
| } | |
| fn is_vowel(c: char) -> bool { | |
| c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment