forked from christianhujer/expensereport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
expensereport.go
55 lines (44 loc) · 1.05 KB
/
expensereport.go
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
package main
import (
"fmt"
"time"
)
type ExpenseType int
const (
Dinner ExpenseType = iota + 1
Breakfast
CarRental
)
type Expense struct {
Type ExpenseType
Amount int
}
func PrintReport(expenses []Expense) {
total := 0
mealExpenses := 0
fmt.Printf("Expenses %s\n", time.Now().Format("2006-01-02"))
for _, expense := range expenses {
if expense.Type == Dinner || expense.Type == Breakfast {
mealExpenses += expense.Amount
}
var expenseName string
switch expense.Type {
case Dinner:
expenseName = "Dinner"
case Breakfast:
expenseName = "Breakfast"
case CarRental:
expenseName = "Car Rental"
}
var mealOverExpensesMarker string
if expense.Type == Dinner && expense.Amount > 5000 || expense.Type == Breakfast && expense.Amount > 1000 {
mealOverExpensesMarker = "X"
} else {
mealOverExpensesMarker = " "
}
fmt.Printf("%s\t%d\t%s\n", expenseName, expense.Amount, mealOverExpensesMarker)
total += expense.Amount
}
fmt.Printf("Meal expenses: %d\n", mealExpenses)
fmt.Printf("Total expenses: %d\n", total)
}