Hye..im having a problem in programming.i have 4 float variables like R1, R2, R3 and R4. All this variables will be print out on the serial monitor after doing some functions. now i want take the highest values from the 4 values and it should be named as R. how to program it?thank you.
Something like this
R = R1;
if (R2 > R) {
R = R2;
}
if (R3 > R) {
R = R3;
}
if (R4 > R) {
R = R4;
}
Serial.println(R);
...R
Any time you have numbers in your variable names you should consider using an array.
float R = max(max(max(R1, R2), R3), R4);
Or, by combining the great idea of MorganS
float valuesWithMeaning[] = {1.2, 12.3, 123.4, 1234.5};
const byte NrValuesWithMenaing = sizeof(valuesWithMeaning)/sizeof(valuesWithMeaning[0]);
float masterValue;
for(byte i = 1; i < NrValuesWithMenaing; i++){
masterValue = max(valuesWithMeaning[i], valuesWithMeaning[i - 1]);
}
Also note, a name like R is pretty stupid. Give it a useful name. Single letter variables are only useful very local as an index for example where it's clear what it does.
thank you for all..