My sketch won't compile

I’m combining ultrasonic sensor and stepper motor sketches to eventually drive a robot. I can’t get the thing to compile. Each ran fine independantly.

Here are the errors:
50: error: ‘microsecondsToInches’ was not declared in this scope
54: error: a function-definition is not allowed here before ’ { ’ token

I’ve played around with putting statements in and out of setup and loop but I don’t fully understand what’s going on.

Any suggestions or info to correct my ways would be greatly appreciated.

Here is the code:

[
#include <Stepper.h>

#define motorSteps 200  
#define motorPin1 8
#define motorPin2 9
#define motorPin3 10
#define motorPin4 11
#define motorPin5 4
#define motorPin6 5
#define motorPin7 6
#define motorPin8 7


// Ping setup  for output and input:
const int pingoutPin = 2;
const int pinginPin = 3;

// initialize of the Stepper library:
Stepper myStepper(motorSteps, motorPin1 ,motorPin3, motorPin2, motorPin4); 
Stepper myStepper2(motorSteps, motorPin5 ,motorPin7, motorPin6, motorPin8);
void setup() {
  // set the motor speed at 60 RPMS:
  myStepper.setSpeed(120);
  myStepper2.setSpeed(120);
  // Initialize the Serial port:
  Serial.begin(9600);
}

void loop() {
 // establish variables for duration of the ping, 
  // and the distance result in inches 
  long inches = 0, duration = 0;

  // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(pingoutPin, OUTPUT);
  digitalWrite(pingoutPin, LOW);
  delayMicroseconds(2);
  digitalWrite(pingoutPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(pingoutPin, LOW);
  
  //Get length of time for the pulse
  pinMode(pinginPin, INPUT);
  duration = pulseIn(pinginPin, HIGH);

  // convert the time into a distance
  inches = microsecondsToInches(duration);
 
long microsecondsToInches(long microseconds)
{
  // According to Parallax's datasheet for the PING, there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  return microseconds / 74 / 2;
}  
  // Step forward 500 steps:

  myStepper.step(500);
  myStepper2.step(500);
  delay(10)
}


/code]

You shouldn't be trying to define a function inside another function.

Move this to somewhere outside the loop() function:

long microsecondsToInches(long microseconds)
{
  // According to Parallax's datasheet for the PING, there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  return microseconds / 74 / 2;
}

get the microsecondsToInches() function out of the loop() function, and put a ";" at the end of the delay(10) line, and it compiles

Thanks, it worked. I didn't pay attention to the structure of the ping sketch when I was combining them.