mercredi 30 octobre 2019

How to find the minimum vale between three (for loop)?

I need to find the minimum value between sonarRange[i], sonarRange2[i] and sonarRange3[i].Each one of the three previous arrays is in an individual (for loop) as it showed the code

I used the If statement to calculate the minimum value. It works but I wrote many codes.

    for (int i = 0; i < 8; i++)
    {
        sonarSensor[i] = robot.getSonarReading(i);
        sonarRange[i] = sonarSensor[i]->getRange();

    }
    for (int i = 0; i < 8; i++) {
        sonarSensor[i] = robot.getSonarReading(i);
        sonarRange2[i] = sonarSensor[i]->getRange();

        }

    for (int i = 0; i < 8; i++) {
        sonarSensor[i] = robot.getSonarReading(i);
        sonarRange3[i] = sonarSensor[i]->getRange();

        }

Aucun commentaire:

Enregistrer un commentaire