-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
66 lines (53 loc) · 1.37 KB
/
main.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use std::io;
struct Aliment{
name: String,
kal: u32,
}
fn main() {
read_calories_from_keybord();
let mut v: Vec<Aliment> = Vec::new();
let apple=Aliment { name: String::from("apple"), kal:55,};
let orange=Aliment { name: String::from("orange"), kal:60,};
let sanwich=Aliment { name: String::from("sanwich"), kal:100,};
let juice=Aliment { name: String::from("juice"), kal:120,};
v.push(apple);
v.push(orange);
v.push(sanwich);
v.push(juice);
let mut n=v.len();
println!("{}",n);
//let mut i=0;
for i in 0..n{
println!("Numele alimentului {}",v[i].name);
}
// while i<2{
//let mut indx1={ let i=i;
//i+1};
//let mut indx2={ let n=v.len();
//n-1};
//println!("Numele alimentului {}",v[n].name);
//}
}
fn read_calories_from_keybord(){
println!("Welcome!");
loop{
println!("Enter the number of calories:");
let mut cal = String::new();
io::stdin()
.read_line(&mut cal)
.expect("Failed to read line");
let cal: u32 = match cal.trim().parse() {
Ok(num) => num,
Err(_) => {
println!("This is not a valid number");
continue;
}
};
println!("The number of calories you entered are: {}", cal);
break;
}
}
fn build_list_of_aliments(){
//let a:[Aliment;10];
//a[0]=Aliment { name: String::from("apple"), kal:55,};
}