Hello! I'm working on this assignment that wants us to write a program that assignment 40 random numbers between 50 and 100 to an array. We then have to print out the average of the maximum and minimum values in the array. I'm using Xcode and it says there are no errors but it won't compile. I can't find the error either :( My main problem is that I'm not sure how to populate the array... I'm sure my function for populateArray is incorrect but I don't know how to fix it. can someone help me out?
Line 28: You're using the same variable name for your loop variable as you have for the argument. Not a good practice. Why have you hard-coded 40 as the limit for the array? Shouldn't you be using the the argument passed in?
Line 30: The assignment says to generate numbers between 50 and 100. Your statement is going to generate numbers between 50 and 150.
array[i] = 50 + rand() % 50;
Line 59: You're doing integer division. If you want a floating point result, you should be doing floating point division as elaleph suggested.
there are no errors but it won't compile
That statement makes no sense. If you have no errors, it should execute. If you have errors, it won't execute. Program compiles and executes for me as written.