Coding for Robotic arm

Need help with my robotic arm coding to simulate malfunction through random number

#include<Braccio.h>
#include<Servo.h>
Servo base;
Servo shoulder;
Servo elbow;
Servo wrist_ver;
Servo wrist_rot;
Servo gripper;
long randNumber;

void setup(){
Braccio.begin();
Serial.begin(9600);
}

if(Serial.available()){
char val = (char) Serial.read();
if(val == 'l'){
Random();
if( randNumber == 15){
Malfunc();
}
}
else
{
lift(); //lift the object at 1 drop at 2
}
}

void lift(){
Braccio.ServoMovement(20, 90, 90, 180, 180, 0, 10);
Braccio.ServoMovement(20, 90, 90, 180, 180, 0, 73);
Braccio.ServoMovement(20, 45, 45, 180, 180, 0, 73);
Braccio.ServoMovement(20, 0, 45, 180, 180, 0, 73);
Braccio.ServoMovement(20, 0, 90, 180, 180, 0, 73);
Braccio.ServoMovement(20, 0, 90, 180, 180, 0, 10);
Braccio.ServoMovement(20, 0, 45, 180, 180, 0, 10);
Braccio.ServoMovement(20, 90, 45, 180, 180, 0, 10);
}

void Malfunc(){
Braccio.ServoMovement(20, 90, 180, 180, 180, 0, 10);
Braccio.ServoMovement(20, 90, 180, 180, 180, 0, 73);

}

void Random() {
// print a random number from 10 to 19
randNumber = random(10, 20);
}

./opt/arduino-builder/arduino-builder -compile -core-api-version 10611 -build-path /tmp/694723888/build -hardware opt/arduino-builder/hardware -hardware ./opt/cores -tools opt/arduino-builder/tools -tools ./opt/tools -built-in-libraries opt/libraries/latest -libraries /tmp/694723888/pinned -libraries /tmp/694723888/custom -fqbn arduino:avr:uno -build-cache /tmp -logger humantags -verbose=false /tmp/694723888/sketch_feb6a

Multiple libraries were found for "Servo.h"

Used: /home/admin/builder/opt/libraries/latest/servo-1-1-2

Not used: /home/admin/builder/opt/libraries/latest/printoo_library-1-0-2

/tmp/694723888/sketch_feb6a/sketch_feb6a.ino:16:3: error: expected unqualified-id before 'if'

if(Serial.available()){

^

exit status 1

Much Appreciated

void setup()
{
  Braccio.begin();
  Serial.begin(9600);
}

if (Serial.available())

You have code outside of a function which is not allowed

It may not cause a problem but you should really sort out the fact that you have multiple copies of teh Servo library

Solved, thanks

UKHeliBob:

void setup()

{
  Braccio.begin();
  Serial.begin(9600);
}

if (Serial.available())




You have code outside of a function which is not allowed

It may not cause a problem but you should really sort out the fact that you have multiple copies of teh Servo library

Yeah, just realized that, thank you so much

Note how putting each { and } on its own line helps see the code blocks