[SOLVED] New to Programing, Please help with classwork assignment!

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.

Please help with classwork assignment!

Extra credit for being honest. :slight_smile:

I keep getting a lot of errors

What errors?

Some clues for things to look at

if statements require that the test be put in brackets
FindMax is a function so you cannot assign a variable to it. That is not how you return values from a function in C
No values are being returned from the FindMin and FindMax functions
When you call a function then the function name must be followed by brackets. possibly with parameters inside them.
Declaring variables inside loop() does not guarantee that they are set to zero
Like statements Serial.print() must be terminated with a se
Your for loops only test 4 values not 5micolon
else does not actually test anything unless followed by if
You may lose marks because the numbers in the array, whilst defined as floats may just as well be ints or even bytes

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];
  }
}
}
 if(MaxNum > ParamArray[i]

Missing right parenthesis

FindMax = ParamArray[i];

You cannot set a function to a value, I believe what you trying to do is this…

MaxNum = ParamArray[i];

Same for FindMin() function

You have a return type of float for your functions, but you return nothing, add this to the bottom of the FindMax() function, similar for FindMin() function

return MaxNum;
MyMax = FindMax;
MyMin = FindMin;

This is wrong, try this

MyMax = FindMax(MyArray);
MyMin = FindMin(MyArray);
Serial.print("The max is: ", MyMax);
Serial.print("The min is: ", MyMin);

This is wrong, try this

Serial.print("The max is: ");
Serial.println(MyMax);
Serial.print("The min is: ");
Serial.println(MyMin);
     if (UserInput == '0')
 {Serial.print (MyMax)};
 }
 {
   else (UserInput == '9')
 { Serial.print (MyMin)
};

Your semicolons belong at the end of the function, not after the curly brace…

for(int i=5; i=>0; i--)
 { 
   if( MinNum = ParamArray[i])

Three problems here, first => should be >=
and the = character means assignment, while == means compare equal to
and if you set i=5; then you will be trying to access ParamArray[5] which does not exist, you may have 5 elements, but they go from 0,1,2,3,4, not 5
Try this

for(int i=4; i>=0; i--)
 { 
   if( MinNum == ParamArray[i])
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);
 }
}

This segment of code is not contained inside anything, not even the loop() function. This means that it will not only never be called, but throw alot of errors because you ONLY put definitions and declarations in the global scope, not if/else/for/while/do while/switch/… etc
Bring the closing curly brace for loop() down to underneath this segment of code

There are other issues with your code from a “proper coding” point of view, but this should fix all of your errors

Be careful of the use of = and == in an if comparison statement. This is a trap for all players.

Hint 0: Use the Tools/AutoFormat command to format your code. It will make some types of errors much clearer.

Hint 1: When looking at a bewildering list of errors like:

/var/folders/jz/5yb8f2hr8xjcpf0059bsfz4r0000gn/T/build3562796045939196121.tmp/sketch_mar15a.cpp.o 
sketch_mar15a.ino: In function 'float FindMax(float*)':
sketch_mar15a.ino:13:3: error: expected ')' before '{' token
sketch_mar15a.ino:16:3: error: expected primary-expression before '}' token
sketch_mar15a.ino:16:3: error: expected ';' before '}' token
sketch_mar15a.ino: In function 'float FindMin(float*)':
sketch_mar15a.ino:22:22: error: expected primary-expression before '>' token
sketch_mar15a.ino:26:15: error: assignment of function 'float FindMin(float*)'
sketch_mar15a.ino:26:15: error: cannot convert 'float' to 'float(float*)' in assignment
sketch_mar15a.ino: In function 'void loop()':
sketch_mar15a.ino:36:9: error: cannot convert 'float(float*)' to 'float' in assignment
sketch_mar15a.ino:37:9: error: cannot convert 'float(float*)' to 'float' in assignment
sketch_mar15a.ino:38:37: error: call of overloaded 'print(const char [13], float&)' is ambiguous
sketch_mar15a.ino:38:37: note: candidates are:
In file included from /Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Stream.h:26:0,
                 from /Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/HardwareSerial.h:29,
                 from /Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Arduino.h:223,
                 from sketch_mar15a.ino:1:
/Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Print.h:62:12: note: size_t Print::print(unsigned char, int) <near match>
     size_t print(unsigned char, int = DEC);
            ^
/Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Print.h:62:12: note:   no known conversion for argument 1 from 'const char [13]' to 'unsigned char'
/Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Print.h:63:12: note: size_t Print::print(int, int) <near match>
     size_t print(int, int = DEC);
            ^
/Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Print.h:63:12: note:   no known conversion for argument 1 from 'const char [13]' to 'int'
/Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Print.h:64:12: note: size_t Print::print(unsigned int, int) <near match>
     size_t print(unsigned int, int = DEC);
            ^
/Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Print.h:64:12: note:   no known conversion for argument 1 from 'const char [13]' to 'unsigned int'
/Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Print.h:65:12: note: size_t Print::print(long int, int) <near match>
     size_t print(long, int = DEC);
            ^
/Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Print.h:65:12: note:   no known conversion for argument 1 from 'const char [13]' to 'long int'
/Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Print.h:66:12: note: size_t Print::print(long unsigned int, int) <near match>
     size_t print(unsigned long, int = DEC);
            ^
/Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Print.h:66:12: note:   no known conversion for argument 1 from 'const char [13]' to 'long unsigned int'
sketch_mar15a.ino:39:37: error: call of overloaded 'print(const char [13], float&)' is ambiguous
sketch_mar15a.ino:39:37: note: candidates are:
In file included from /Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Stream.h:26:0,
                 from /Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/HardwareSerial.h:29,
                 from /Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Arduino.h:223,
                 from sketch_mar15a.ino:1:
/Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Print.h:62:12: note: size_t Print::print(unsigned char, int) <near match>
     size_t print(unsigned char, int = DEC);
            ^
/Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Print.h:62:12: note:   no known conversion for argument 1 from 'const char [13]' to 'unsigned char'
/Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Print.h:63:12: note: size_t Print::print(int, int) <near match>
     size_t print(int, int = DEC);
            ^
/Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Print.h:63:12: note:   no known conversion for argument 1 from 'const char [13]' to 'int'
/Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Print.h:64:12: note: size_t Print::print(unsigned int, int) <near match>
     size_t print(unsigned int, int = DEC);
            ^
/Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Print.h:64:12: note:   no known conversion for argument 1 from 'const char [13]' to 'unsigned int'
/Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Print.h:65:12: note: size_t Print::print(long int, int) <near match>
     size_t print(long, int = DEC);
            ^
/Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Print.h:65:12: note:   no known conversion for argument 1 from 'const char [13]' to 'long int'
/Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Print.h:66:12: note: size_t Print::print(long unsigned int, int) <near match>
     size_t print(unsigned long, int = DEC);
            ^
/Applications/arduino/Arduino-1.6.0.app/Contents/Resources/Java/hardware/arduino/avr/cores/arduino/Print.h:66:12: note:   no known conversion for argument 1 from 'const char [13]' to 'long unsigned int'
sketch_mar15a.ino: At global scope:
sketch_mar15a.ino:41:1: error: expected unqualified-id before 'if'
Error compiling.

You need to look at the VERY FIRST error that happens, because the compiler is stupid and once it detects a mistake, it has a lot of trouble figuring out that where it should start up again looking for the next error. (and in fact you get those really confusing reports of errors in the Arduino core files…)

In this case, you need to look at:

sketch_mar15a.ino: In function 'float FindMax(float*)':
sketch_mar15a.ino:13:3: error: expected ')' before '{' token

If you look at line 13 of your sketch, you should see a pretty obvious missing closed paren, just like it says.
Then you compile again, and look at the FIRST error again (yeah, your sketch has more than one problem.)