aboutsummaryrefslogtreecommitdiff
path: root/challenge-279/zapwai/rust/ch-2.rs
blob: c601369f01dd32ec1a012b7e7988bec20bcd7ffe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
fn main() {
    let str = "perl";
    proc(str);
    let str2 = "book";
    proc(str2);
    let str3 = "goodmorning";
    proc(str3);
}

fn is_vowel(c: char) -> bool {
    if c == 'a' ||
	c == 'e' ||
	c == 'i' ||
	c == 'o' ||
	c == 'u' {
	    return true;
	}
    return false;
}

fn proc(str : &str) {
    println!("Input: str = {str}");
    let mut cnt = 0;
    for c in str.chars() {
	if is_vowel(c) {
	    cnt += 1;
	}
    }
    print!("Output:");
    if cnt % 2 == 0 {
	println!(" true");
    } else {
	println!(" false");
    }
}