-
-
Save bDrwx/7c1a05fad766fdc0544e966be27a6197 to your computer and use it in GitHub Desktop.
A small program that takes a word (String) as input and translates it into Pig Latin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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