Hello, my question is how to find the minimum value of a set of numbers in a loop. I used a for loop, and the maximum value is always right but the minimum is always 0. I think it's because the minValue is set to 0 to begin with so it thinks it's an input and not just the starter value. This is my code
any help would be greatly appreciated
Code:
#include <stdio.h>
#include <stdlib.h>
#define pause system("pause")
#define LOOPMAX 5
int main() {
int loopCounter = 0;
float maxNum = 0.0;
float num = 0.0;
float minNum = 0.0;
for (loopCounter = 0; loopCounter <LOOPMAX; loopCounter++) {
printf("Enter a Number: ");
scanf("%f" ,&num);
if (num>=maxNum) {
maxNum=num;
}
if (num<=minNum) {
minNum=num;
}
} //end loop
printf("The Maximum of the values entered is %.2f.\n" ,maxNum);
printf("The Minimum of the values entered is %.2f.\n" ,minNum);
pause;
}
any help would be greatly appreciated
Comment