-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcatalog.ion
More file actions
31 lines (27 loc) · 800 Bytes
/
Copy pathcatalog.ion
File metadata and controls
31 lines (27 loc) · 800 Bytes
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
struct Product {
unit_price: int;
quantity: int;
}
fn line_total(product: Product) -> int {
return product.unit_price * product.quantity;
}
pub fn catalog_line_count() -> int {
return 3;
}
pub fn catalog_grand_total() -> int {
let row0: Product = Product { unit_price: 1200, quantity: 2 };
let row1: Product = Product { unit_price: 350, quantity: 5 };
let row2: Product = Product { unit_price: 99, quantity: 10 };
let total0: int = line_total(row0);
let total1: int = line_total(row1);
let total2: int = line_total(row2);
return total0 + total1 + total2;
}
pub fn catalog_units_in_stock() -> int {
let quantities: [int; 3] = [2, 5, 10];
let mut units: int = 0;
for qty in quantities {
units = units + qty;
}
return units;
}