tmp (978B)
1 #include "util.h" 2 3 int 4 input_time(const char *order, const char *sport) { 5 int i; 6 SEprintf("How many %s did %s take: ", order, sport); 7 i = readint(); 8 SEprintf("\n"); 9 return i; 10 } 11 12 void 13 readtime(const char *sport, int secs[], int mins[], int hours[], int i) { 14 secs[i] = input_time("secs", sport); 15 mins[i] = input_time("mins", sport); 16 hours[i] = input_time("hours", sport); 17 } 18 19 int 20 sum(int arr[3]) { 21 int total = 0; 22 for (int i = 0; i < 3; i++) 23 total += arr[i]; 24 25 return total; 26 } 27 28 void 29 setup() { 30 int secs[3] = {0}, mins[3] = {0}, hours[3] = {0}, res[3] = {0}; 31 char *sports[] = { 32 "swim", 33 "run", 34 "cycle", 35 }; 36 37 Serial.begin(9600); 38 39 for (int i = 0; i < SIZE(sports); i++) 40 readtime(sports[i], secs, mins, hours, i); 41 42 res[0] = sum(secs); 43 res[1] = sum(mins); 44 res[2] = sum(hours); 45 46 for (int i = 0; i <= 3; i++) { 47 res[i + 1] += res[i] / 60; 48 res[i] = res[i] % 60; 49 } 50 51 SEprintf("Total time: %dhr %dmin %dsec.\n", res[2], res[1], res[0]); 52 } 53 54 void loop() {}