void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
const int HOUR_MULTIPLIER = 3600;
const int MIN_MULTIPLIER = 60;
long total_secs [4];
String names[4] = ("swim", "run", "bike", "total");
//declaring all variables in the program
Serial.println("please enter the time taken");
Serial.println("swimming hours, minutes and seconds. Enter the same for bike and run");
while (!Serial.available()) {};
total_secs [0] = Serial.parseInt() * HOUR_MULTIPLIER;
while (!Serial.available()) {};
total_secs [0] += Serial.parseInt() * MIN_MULTIPLIER;
while (!Serial.available()) {};
total_secs [0] += Serial.parseInt();
while (!Serial.available()) {};
total_secs [1] = Serial.parseInt() * HOUR_MULTIPLIER;
while (!Serial.available()) {};
total_secs[1] += Serial.parseInt() * MIN_MULTIPLIER;
while (!Serial.available()) {};
total_secs [1] += Serial.parseInt();
while (!Serial.available()) {};
total_secs [2] = Serial.parseInt() * HOUR_MULTIPLIER;
while (!Serial.available()) {};
total_secs [2] += Serial.parseInt() * MIN_MULTIPLIER;
while (!Serial.available()) {};
total_secs [2] += Serial.parseInt();
total_secs [3] = total_secs [0] + total_secs [1] + total_secs [2];
for (int index = 0; index < 4; index++) {
Serial.println(names[index]);
Serial.print(" hours ");
Serial.print(total_secs[index] / HOUR_MULTIPLIER);
total_secs[index] = total_secs[index] % HOUR_MULTIPLIER;
Serial.print( " minutes " );
Serial.print(total_secs[index] / MIN_MULTIPLIER);
total_secs[index] = total_secs[index] % MIN_MULTIPLIER;
Serial.print(" seconds ");
Serial.println(total_secs[index]);
}
}
void loop() {
// put your main code here, to run repeatedly:
}