Almost there. Wrong Output

void setup() {
  Serial.begin(9600);
  

// SWIM TIMES


  Serial.println("Enter Swim Hours");

  int totalSwimHours;
 while (!Serial.available()) {
 //wait for a the user to enter a value
 ;
 }
 totalSwimHours = Serial.parseInt();


  Serial.println("Enter Swim Minutes");
 
 int totalSwimMinutes;
 while (!Serial.available()) {
 //wait for a the user to enter a value
 ;
 }
 totalSwimMinutes = Serial.parseInt();
 

  Serial.println("Enter Swim Seconds");
  
 int totalSwimSeconds;
 while (!Serial.available()) {
 //wait for a the user to enter a value
 ;
 }
 totalSwimSeconds = Serial.parseInt();

int hourSwimResult;
hourSwimResult = totalSwimSeconds + totalSwimMinutes * 60 + totalSwimHours * 3600;
int minuteSwimResult;
minuteSwimResult = totalSwimSeconds + totalSwimMinutes * 60 + totalSwimHours * 3600;
int secondSwimResult;
secondSwimResult = totalSwimSeconds + totalSwimMinutes * 60 + totalSwimHours * 3600;

 Serial.println("-----------------");
 

// BIKE TIMES


  Serial.println("Enter Bike Hours");
 
 int totalBikeHours;
 while (!Serial.available()) {
 //wait for a the user to enter a value
 ;
 }
 totalBikeHours = Serial.parseInt();


  Serial.println("Enter Bike Minutes");

 int totalBikeMinutes;
 while (!Serial.available()) {
 //wait for a the user to enter a value
 ;
 }
 totalBikeMinutes = Serial.parseInt();

 
  Serial.println("Enter Bike Seconds");
  
 int totalBikeSeconds;
 while (!Serial.available()) {
 //wait for a the user to enter a value
 ;
 }
 totalBikeSeconds = Serial.parseInt();

 int hourBikeResult;
hourBikeResult = totalBikeSeconds + totalBikeMinutes * 60 + totalBikeHours * 3600;
int minuteBikeResult;
minuteBikeResult = totalBikeSeconds + totalBikeMinutes * 60 + totalBikeHours * 3600;
int secondBikeResult;
secondBikeResult = totalBikeSeconds + totalBikeMinutes * 60 + totalBikeHours * 3600;

 Serial.println("-----------------");

  
// RUN TIMES


  Serial.println("Enter Run Hours");
 
 int totalRunHours;
 while (!Serial.available()) {
 //wait for a the user to enter a value
 ;
 }
 totalRunHours = Serial.parseInt();


  Serial.println("Enter Run Minutes");
 
 int totalRunMinutes;
 while (!Serial.available()) {
 //wait for a the user to enter a value
 ;
 }
 totalRunMinutes = Serial.parseInt();

 
   Serial.println("Enter Run Seconds");
  
 int totalRunSeconds;
 while (!Serial.available()) {
 //wait for a the user to enter a value
 ;
 }
 totalRunSeconds = Serial.parseInt();

int hourRunResult;
hourRunResult = totalRunSeconds + totalRunMinutes * 60 + totalRunHours * 3600;
int minuteRunResult;
minuteRunResult = totalRunSeconds + totalRunMinutes * 60 + totalRunHours * 3600;
int secondRunResult;
secondRunResult = totalRunSeconds + totalRunMinutes * 60 + totalRunHours * 3600;

 Serial.println("-----------------");

// Total of everything

Serial.println ("Total Time:");

 int totalHours;
totalHours = (hourRunResult = totalRunSeconds + totalRunMinutes * 60 + totalRunHours * 3600) +
(hourBikeResult = totalBikeSeconds + totalBikeMinutes * 60 + totalBikeHours * 3600) +
(hourSwimResult = totalSwimSeconds + totalSwimMinutes * 60 + totalSwimHours * 3600);

Serial.print  (totalHours / 3600);
Serial.print  ("hr");
Serial.print  (" ");

 int totalMinutes;
totalMinutes = (minuteRunResult = totalRunSeconds + totalRunMinutes * 60 + totalRunHours * 3600) +
(minuteBikeResult = totalBikeSeconds + totalBikeMinutes * 60 + totalBikeHours * 3600) +
(minuteSwimResult = totalSwimSeconds + totalSwimMinutes * 60 + totalSwimHours * 3600);

Serial.print  (totalHours % 3600 / 60);
Serial.print  ("min");
Serial.print  (" ");

 int totalSeconds;
totalSeconds = (secondRunResult = totalRunSeconds + totalRunMinutes * 60 + totalRunHours * 3600) +
(secondBikeResult = totalBikeSeconds + totalBikeMinutes * 60 + totalBikeHours * 3600) +
(secondSwimResult = totalSwimSeconds + totalSwimMinutes * 60 + totalSwimHours * 3600);

Serial.print  (totalSeconds % 60);
Serial.print  ("sec");



// Times to input Hr/Min/Sec :

// Test 1 : 0 50 59 
//          2 50 59 
//          1 50 59  =  5hr 32min 57sec
            
// Test 2 : 0 50 59 
//          0 170 59 
//          0 110 59 =  5hr 32min 57sec
            
// Test 3 : 2 50 02 
//          9 20 53 
//          6 42 59  =  18hr 53min 54sec
// But it's outputting = 0hr 41min 38sec
 
 
}



void loop() {
  // put your main code here, to run repeatedly:

}

Firstly,

I’d like to thank anyone who offered suggestions the other day to help me with my assignment.

I have scrapped a lot of the pointless code that wasn’t needed and organised it a little better and 2/3 of my outputs are outputting correctly.

Test 3 is not for some reason.

Test 3 :

Swim Times = 2 hrs 50 Mins 02 Secs

Bike Times = 9 hrs 20 Mins 53 Secs

Run Times = 6 hrs 42 Mins 59 Secs

Expected Output:

18hr 53min 54sec

Actual Output:

0hr 41min 38sec

I’m assuming the math is wrong somewhere, but I can’t seem to see it.

If someone could help me figure this out and find out why I’m getting the wrong output that would be great.

ALSO, I am aware I can use loops and other things, however the assignment I’m doing DOES NOT permit me to use them

Thanks in advance.

You are doing all you math in 16-bit integers. The largest value a 16-bit integer can store is 32767. You are multiplying your hour values by 3600. For value of hour greater than 9.1 you will get an integer overflow and some of your values will turn negative.

If you switch the time values to "unsigned int" you could store up to 65535. Then your values won't overflow until you reach 18.2 hours. If you want to measure the time in seconds and you anticipate totals greater than 18.2 hours you should switch everything to "unsigned long".