-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy path019.rs
45 lines (33 loc) · 1.17 KB
/
019.rs
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
37
38
39
40
41
42
43
44
45
/*
Desafio 019
Problema: Um professor quer sortear um dos seus quatro alunos para
apagar o quadro. Faça um programa que ajude ele, lendo o
nome dos alunos e escrevendo na tela o nome do escolhido.
*/
/*
AVISO: Rand não é uma biblioteca padrão do Rust, é necessário a
utilização do Cargo para sua instalação e execução.
*/
use rand::Rng;
fn main() {
let mut names = Vec::new();
let mut aluno1 = String::new();
let mut aluno2 = String::new();
let mut aluno3 = String::new();
let mut aluno4 = String::new();
println!("Digite o nome do aluno 1: ");
std::io::stdin().read_line(&mut aluno1).unwrap();
println!("Digite o nome do aluno 2: ");
std::io::stdin().read_line(&mut aluno2).unwrap();
println!("Digite o nome do aluno 3: ");
std::io::stdin().read_line(&mut aluno3).unwrap();
println!("Digite o nome do aluno 4: ");
std::io::stdin().read_line(&mut aluno4).unwrap();
names.push(aluno1);
names.push(aluno2);
names.push(aluno3);
names.push(aluno4);
let mut rng = rand::thread_rng();
let index = rng.gen_range(0..names.len());
println!("O aluno escolhido foi {}", names[index]);
}