vendredi 28 septembre 2018

Need help debugging

The function I'm trying to produce is called:

int Range(int values[], int numValues)

The purpose is to return the difference between the largest value in the array and the smallest value in the array.

Below is my code however it doesn't work. Any help would be appreciated :)

#include <stdio.h>

int Range(int values[], int numValues)
{
    int i;
    int large;
    int small;
    int displayone;
    int displaytwo;
    int calc;

    large = values[0];
    small = values[0];

    for(i=0;i<numValues;i++){

        if(values[i]>large){
            displayone = values[i];
        }
        else if(values[i] < small){
            displaytwo = values[i];
        }
    }

    calc = displayone - displaytwo;

    return calc;
}

Aucun commentaire:

Enregistrer un commentaire