-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanda_time.c
76 lines (54 loc) · 1.53 KB
/
panda_time.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
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
67
68
69
70
71
72
73
#include "header.h"
/*************** functions ***************/
/*
* int number_of_days()
* function ask and display the total number of days spent on the trip
* return an integer of The total number of days spent on the trip
* Do not accept numbers less than 1 for the number of days.
*/
int number_of_days () {
int num_days;
do {
printf("Please enter the total number of days spent on the trip: ");
scanf("%d", &num_days);
if (num_days < 1) {
printf("Invalid input: the number of days cannot be less than 1.\n");
continue;
}
else {
printf("You spent total %d days on the trip.\n", num_days);
}
} while (num_days < 1);
printf("\n");
return num_days;
}
/**
* @brief function int get_time()
* @return an integer value to represent time from user input
* validate time range 0 to 24
*/
int get_time()
{
int input;
GET_TIME: // label
printf("Please enter the time in 24 hour format: 0 or 24 as 0 am, 12 as 12:00 pm, 13 as 1 pm\n");
scanf(" %d", &input);
if (input < 0) {
printf("Time can not be a negative number.\n");
goto GET_TIME;
} else if (input > 24) {
printf("Time can not exceed 24:00.\n");
goto GET_TIME;
} else {
printf("You enter: %d\n", input);
}
return input;
}
int get_departure_time() {
printf("--- Departure Time ---\n");
return get_time();
}
int get_arrival_time () {
printf("--- Arrival Time ---\n");
return get_time();
}