I’m having trouble trying to figure out what am I doing wrong, Im new to programing, please help me to get this code done :-[
Heres what i need to do:
Give an array of 5 arbitrarily float numbers (e.g., 70.11, ‐42, 1.0, ‐5.3, 1465). Write two functions and use “for” loop and “if” statements to find the max and the min numbers. You can name the functions as “FindMax( )” and “FindMin( )”. Type ‘0’ in Serial Monitor to display the min value in Serial Monitor, and type ‘9’ to display the max number. Display a reminder message to user if any other number or character is being typed, such as "Unexpected input! Please type a number of 0 or 9: “.
Here is what i have so far but I keep getting a lot of errors:
void setup ()
{
Serial.begin (9600);
}
float FindMax (float ParamArray[5]) // To define a function to find maxim
{
float MaxNum = ParamArray[0];
for(int i=1; i<5; i++)
{
if(MaxNum > ParamArray[i]
{
FindMax = ParamArray[i];
}
}
}
float FindMin(float ParamArray[5]) // To define a function to find minim
{
float MinNum = ParamArray[0];
for(int i=5; i=>0; i--)
{
if( MinNum = ParamArray[i])
{
FindMin = ParamArray[i];
}
}
}
void loop()
{
float MyArray[5] = {10,20,30,40,50}; //define the array
float MyMax, MyMin; //declare two variablesto store max and min
MyMax = FindMax;
MyMin = FindMin;
Serial.print("The max is: ", MyMax);
Serial.print("The min is: ", MyMin);
}
if (Serial.available () ) //to check if any number/char typed
{
char UserInput = Serial.read(); //read in a typed number from serial monitor
if (UserInput == '0' || UserInput == '9')
{
{
if (UserInput == '0')
{Serial.print (MyMax)};
}
{
else (UserInput == '9')
{ Serial.print (MyMin)
};
}
}
else
{
Serial.println ("Unexpected Input! please type a number of 0 or 9: ");
Serial.println (UserInput);
}
}
Please help me! thank you so much.