forked from christianhujer/expensereport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExpenseReport.c
41 lines (33 loc) · 1.15 KB
/
ExpenseReport.c
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
#include "ExpenseReport.h"
#include <stdio.h>
#include <time.h>
void printReport(struct Expense expenses[], size_t numExpenses) {
int total = 0;
int mealExpenses = 0;
time_t now;
if (time(&now) == -1)
return;
printf("Expenses %s", ctime(&now));
for (size_t i = 0; i < numExpenses; i++) {
if (expenses[i].type == DINNER || expenses[i].type == BREAKFAST) {
mealExpenses += expenses[i].amount;
}
char *expenseName;
switch (expenses[i].type) {
case DINNER:
expenseName = "Dinner";
break;
case BREAKFAST:
expenseName = "Breakfast";
break;
case CAR_RENTAL:
expenseName = "Car Rental";
break;
}
char *mealOverExpensesMarker = ((expenses[i].type == DINNER && expenses[i].amount > 5000) || (expenses[i].type == BREAKFAST && expenses[i].amount > 1000)) ? "X" : " ";
printf("%s\t%d\t%s\n", expenseName, expenses[i].amount, mealOverExpensesMarker);
total += expenses[i].amount;
}
printf("Meal expenses: %d\n", mealExpenses);
printf("Total expenses: %d\n", total);
}