wondering what the best way of adding a function without breaking the code

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:
}

The best way to do it is first you make an attempt. Then we help you get it right.

So what function? What's it doing? I can't see one anywhere in that code (which is already broken so that's not a good start).

Steve

And the funny little degree symbols (°) would render correctly if code tags </> were used.

Curious, why so many of these?

while (!Serial.available()) {};

And the semi-colon at the end of each one won't help.

And as a side note, all your variables are declared inside the setup(). Thus, they are "local" and can only be accessed by setup(). If, in the future, you need to have them available to other functions, such as loop(), you will have to move them outside of setup(). Thus making them "global".

Ok.
Keep it to one thread (not this one, but this one)
Use code tags (you're a university student, dammit - what happened to simple literacy?)

Thread locked.