Find the highest and lowest number in array with PIC16F877A

Status
Not open for further replies.
min is initialized to 0 in the beginning. So, 0 is the minimum value. Don't initialize min or initialize it to max value you can get. Initialize it to 10000 if your adc values doesn't exceed 10000.
 

else if (array < min)

remove "else" from the line mentioned above from the code.

- - - Updated - - -

min is initailized to zero outside the for loop.

It doesn't affect the value printing.
 

Yes. snishanth. You are right. I didn't see that else. else if has to be replaced by else. If else if is used it only checks the max values and never checks for min values.
 

Yes. snishanth. You are right. I didn't see that else. else if has to be replaced by else. If else if is used it only checks the max values and never checks for min values.

else if has to replaced by if and not else, there is also a chance of else if working well... the only problem is min = 0 initialization.. it can be min = 10000 or some big value..
 

sorry, I mean "else if" should be repalced with "if".
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…