Write a program which has a global array of
integers with values assigned to the array.
• Write a function ‘getArrayMin’ to return the
minimum value in the array.
• Draw a circle in the centre of the window with
the greyscale colour returned by the
getArrayMin function
int myArray[]={25,5,24,6,45,4};
void setup(){
}
void draw(){
println("Smallest",getMin(myArray));
}
int getMin(int x,int y)
{
int hold=x;
if(y<x)
{
hold=y;
}
return hold;
}
You need to pass an array to it, so the way you call the function getMin is actually correct (you call it here: println("Smallest",getMin(myArray));, specifically getMin(myArray)).
But the header of the function doesn’t match it (where you define the function).
Definition of the function is now int getMin(int x,int y) but it should be int getMin(int[] arrMy)
What you have to do in the function
You need to for-loop over the array “arrMy” in the function, so you look at each item in the array.
You can store how small the smallest number is in the variable smallestMy (initially set it very high)
When the next number is smaller than your smallest number up to now, set smallestMy again to the current number