Can't get the simplest of things to work. Help pls I am starting to feel sad :/

So, it's only a really basic program to allow the user to enter Athlete's times in a triathlon, with the fastest time being saved and, when the user wants too, they can exit the loop and have the fastest time displayed. However, I can't get my count to increment correctly, and furthermore when I set count to 1 (As their can't really be an "athlete 0") it updates the vale for FastestTime every time through the loop, instead of only when the current total is larger than FastestTime. I have been beaten by a very basic program and it's a bit depressing really, so if anyone has any clues as to why this is happening and any possible fixes I'd be much obliged, as I can't fathom whats wrong with it.

I am using an Arduino Uno

int swimS = 0;
int swimM = 0;
int swimH = 0;
int bikeS = 0;
int bikeM = 0;
int bikeH = 0;
int runS = 0;
int runM = 0;
int runH = 0;
long total = 0;
long Swim = 0;
long Bike = 0;
long Run = 0;
int call = 0;
const int ConInt1 = 60;
const int ConInt2 = 3600;
int ExitLoop = 0;
long FastestTime = 0;
long FastestAthlete = 0;
int count = 0;

int FnInput(){
int x;
x = 0;
while (!Serial.available()) {
;

}
x = Serial.parseInt();
return x;
}

int FnOutput(){
Swim = swimS + (swimM * ConInt1) + (swimH * ConInt2);
Bike = bikeS + (bikeM * ConInt1) + (swimH * ConInt2);
Run = runS + (runM * ConInt1) + (runH * ConInt2);
total = Swim + Bike + Run;

String namesArray = {"Swim Time: ", "Bike time: ", "Run time: ", "Total time: "};
long SecondsArray[4];
SecondsArray[0]=Swim;
SecondsArray[1]=Bike;
SecondsArray[2]=Run;
SecondsArray[3]=total;

for(int i=0; i<4; i++){
Serial.println(namesArray + (SecondsArray/ConInt2) + "hr " + ((SecondsArray_/ConInt1) % ConInt1) + "min " + (SecondsArray % ConInt1) + “sec.”);
}
}
void setup() {_

Serial.begin(9600);
ExitLoop = 0;
count = 1;
do {
Serial.println(“Please enter the number of seconds for the Swimming:”);
swimS = FnInput();
Serial.println(“Please enter the number of minutes for Swimming:”);
swimM = FnInput();
Serial.println(“Please enter the number of hours for swimming”);
swimH = FnInput();
Serial.println(“Please enter the number of seconds for the Biking:”);
bikeS = FnInput();
Serial.println(“Please enter the number of minutes for Biking:”);
bikeM = FnInput();
Serial.println(“Please enter the number of hours for Biking:”);
bikeH = FnInput();
Serial.println(“Please enter the number of seconds for the Running:”);
runS = FnInput();
Serial.println(“Please enter the number of minutes for Running:”);
runM = FnInput();
Serial.println(“Please enter the number of hours for Running:”);
runH = FnInput();
FnOutput();
if (count = 1){
* FastestTime = total;*
* FastestAthlete = count;*
}
if (FastestTime < total){
* FastestTime = total;*
* FastestAthlete = count;*
}
count++;
Serial.println(FastestTime);
Serial.println(FastestAthlete);
Serial.println(count);
Serial.println(“Enter another athlete?(Enter 0 to continue or 1 to exit)”);
ExitLoop = FnInput();
} while (ExitLoop == 0);
* Serial.print(“The fastest athlete was no.”);*
* Serial.print(FastestAthlete);*
* Serial.print(" with a total time of ");*
* Serial.print(FastestTime / 3600);*
* Serial.print("hr ");*
* Serial.print((FastestTime / 60) % 60);*
* Serial.print("min ");*
* Serial.print(FastestTime % 60);*
* Serial.print(“sec.”);*
}
void loop() {
}

This program runs once then exits. Surely most of it should be between:

void loop() {
//Most of your code should be here surely?

}

This is part of my coursework, and I am directed to keep it inside of void setup and not void loop.

As their can’t really be an “athlete 0”

Oh yes there can if you want there to be
A large portion of your code is in italics because you did not put it in [code] [/code] tags.

The italics have made a particular mess of this line I suspect, but we don’t actually know what your code was originally like.

Serial.println(namesArray + (SecondsArray/ConInt2) + "hr " + ((SecondsArray/ConInt1) % ConInt1) + "min " + (SecondsArray % ConInt1) + "sec.");

As to your problem look hard at this line

if (count = 1)

Don't keep starting new threads on the same old poor code.

Um?

ferraribunny: This is part of my coursework, and I am directed to keep it inside of void setup and not void loop.

re-read the instructions.

is this a training example to show you just what you can do in void setup ?

since voidsetup() runs once, then, unless I am mistaken,

count++;

could only ever return 1

count++;

could only ever return  1

Except that it is in a do/while loop which won't exit unless ExitLoop equals zero.

Re reading the instructions won't achieve anything as this is what the instructions tell me to do, it's just implementing it and getting around this error that's my problem not understand the instruction set. If I put count++ inside of a loop, void setup or no void setup, surely that loop will run and count will be incremented by 1 each time? Not really sure what you meant by that to be honest

And I am assuming that you meant by "look hard at this line" you meant for me to use a double equals?

UKHeliBob:

As their can’t really be an “athlete 0”

Oh yes there can if you want there to be
A large portion of your code is in italics because you did not put it in [code] [/code] tags.

The italics have made a particular mess of this line I suspect, but we don’t actually know what your code was originally like.

Serial.println(namesArray + (SecondsArray/ConInt2) + "hr " + ((SecondsArray/ConInt1) % ConInt1) + "min " + (SecondsArray % ConInt1) + "sec.");

As to your problem look hard at this line

if (count = 1)

Yep, well, that just happened.
I used Visual Basic before I started programming with the Arduino, so the whole double equals is a little bit new to me but yeah, I am not going to tell you how long I spent staring at that code but thank you very much for your help and I can say I will 100% never make that mistake again…

I can say I will 100% never make that mistake again...

Oh yes you will...

Oh no I won't...

ferraribunny: Oh no I won't...

Yeah, you will. And, you'll again spend a bunch of time figuring out why the code doesn't work. It won't even be intentional when it happens.

I've been doing C and C++ coding for 30 years, on a daily basis. Just last week, I made that mistake, and spent 2 hours debugging the code, because I KNOW better than to use = in place of ==.

ferraribunny:
Oh no I won’t…

Oh yes you will! The only way to avoid ever making this mistake again is to stop coding. Especially if you start using other languages where “==” is considered a syntax error.