Skip to content

Instantly share code, notes, and snippets.

@bDrwx
Forked from DenialAdams/pig-latin
Created February 16, 2019 19:51
Show Gist options
  • Save bDrwx/7c1a05fad766fdc0544e966be27a6197 to your computer and use it in GitHub Desktop.
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
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