PROBLEM Generate random numbers using rand() in C
Go to solution
Solved by Sauron,
You don't initialize your .min value before the random part so whatever is in there when you start the program is what it begins with. If that value is lower than all randomly generated values then the program will never enter the if statement. Just initialize the values to the maximum and minimum int values respectively and the problem is solved.
#include <limits.h> /*...*/ int main() { struct elementposition minmax; minmax.min = MAX_INT; minmax.max = MIN_INT; /*...*/

Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now