How can I correct this function compile error?

At the bottom of my code are two functions, I get an error regarding them saying that I cannot place a function definition before the token "{". What needs to be fixed?

... 
...
...
//delay(300);               Motor A and Motor B may have a need for different speeds, depending on the size and shape of each of the various pills we dispense. Use this code if this is necessary
          //analogWrite(motorPinC, 80);
          delay(50); //how long the motors need to run to spit out exactly one pill of each
        }
        else
        {
          delay(10); //debounce the system
          // leave servos B and C stay off on the even(second) run of servo A, meaning that A gives twice a day while B and C give once a day.
          for(servoPosB = 90; servoPosB>=1; servoPosB-=1)     // goes from 180 degrees to 0 degrees 
          {                                
            servoB.write(servoPosB);              // tell servo to go to position in variable 'pos' 
            delay(15); 
          }
          for(servoPosC = 90; servoPosC>=1; servoPosC-=1)     // goes from 180 degrees to 0 degrees 
          {                                
            servoC.write(servoPosC);              // tell servo to go to position in variable 'pos' 
            delay(15); 
          }
          //analogWrite(motorPinB, LOW); //this is a pill that is given only once a day, motor left off
          //analogWrite(motorPinC, LOW); //this is a pill that is given only once a day, motor left off
        } 
      } 
    }
    days++;
  }

  
  //inside the void loop but outside of any of the other loops, these are the functions down here.

  int myprescriptionfunctionA (int days, int iterations)
  {
    int remainingA;
    remainingA = days - iterations;
    return remainingA;
  }
  int myprescriptionfunctionB (int remainingA)
{
    int remainingB;
    remainingB = remainingA/2;
    return remainingB;
  }  
}

T-57: What needs to be fixed?

You really ought to post all your code. It looks like the previous function is incomplete (not enough closing braces)

#include <Servo.h> 

#define NOTE_C2  65
#define NOTE_E2  82
int melody[] = {NOTE_E2, NOTE_C2};
int noteDurations[] = {4, 4};

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display

//int motorPinA = 10;
int ledPinGREEN = 3;
int ledPinRED = 2;
int ledPinYELLOW = 1;
int repetitions = 0;
int iterations = 0;
int days = 0;
int remainingA = 0;
int remainingB = 0;


//int motorPinB = 5;
//int motorPinC = 8;
//int servoA;
//int servoB;
//int servoC;

Servo servoA;
Servo servoB;
Servo servoC;
// Sweep
// by BARRAGAN <http://barraganstudio.com> 
// This example code is in the public domain.
//Servo myservo;  // create servo object to control a servo 
// a maximum of eight servo objects can be created 
int servoPosA = 0;    // variable to store the servo position, all sevo positions start at zero, as they should.
int servoPosB = 0;
int servoPosC = 0;

void setup()
{
  int ledPinGREEN;
  int ledPinRED;
  int ledPinYELLOW;
  //int motorPin;
  //pinMode (motorPinA, OUTPUT);
  pinMode(ledPinGREEN, OUTPUT);
  pinMode(ledPinRED, OUTPUT);
  pinMode(ledPinYELLOW, OUTPUT);
  int repetitions;
  int iterations;
  int days;
  int myservo;
  //int motorPinB;
  //pinMode(motorPinB, OUTPUT);
  servoA.attach(5);  // attaches the servo (A) on pin 5 to the servo object 
  servoB.attach(8);  // a servo (B) is attached to pin 8
  servoC.attach(9);  // a servo (C) is attached to pin 9
}

void loop()
{
  lcd.init();     // initialize the LCD 
  // Print a message to the LCD.
  lcd.backlight();
  lcd.print("remainingA(), remainingB()"); //make the LCD display the remaining pills in the prescription

    for(int days=0;days<40;days++)
  {
    if(iterations % 2 == 0)
    {
      analogWrite(ledPinGREEN, 1023);
    }
    else
    {
      analogWrite(ledPinRED, 1023);
    }
    if(iterations >= 2)
    {
      //analogWrite(motorPinA, LOW);
      analogWrite(ledPinYELLOW, 0);
      //Servo A needs to go to zero, 0, closed, and stay there      
      for(servoPosA = 90; servoPosA>=1; servoPosA-=1)     // goes from 180 degrees to 0 degrees 
      {                                
        servoA.write(servoPosA);              // tell servo to go to position in variable 'pos' 
        delay(15); 
      }
    }
    else
    {
      for(int repetitions=0;repetitions<2;repetitions++)
      {
        delay(500);
        analogWrite(ledPinYELLOW, 1000);
        delay(500);
        //Servo A needs to go to 90 degrees, open
        for (int thisNote = 0; thisNote < 2; thisNote++)
        {
          int noteDuration = 1000/noteDurations[thisNote];
          tone(8, melody[thisNote],noteDuration);
          int pauseBetweenNotes = noteDuration;
          delay(pauseBetweenNotes);
          // stop the tone playing:
          noTone(8);
        }
        for(servoPosA = 0; servoPosA < 90; servoPosA += 1)  // goes from 0 degrees to 180 degrees 
        {                                  // in steps of 1 degree 
          servoA.write(servoPosA);              // tell servo to go to position in variable 'pos' 
          delay(15);                       // waits 15ms for the servo to reach the position 
        } 
        for(servoPosA = 90; servoPosA>=1; servoPosA-=1)     // goes from 180 degrees to 0 degrees 
        {                                
          servoA.write(servoPosA);              // tell servo to go to position in variable 'pos' 
          delay(15); 
        }
        //analogWrite(motorPinA, 70);
        delay (500);
        analogWrite(ledPinYELLOW, 0);
        //servo A needs to be at 0, closed
        //analogWrite(motorPinA, LOW);
        iterations++;        
        {
          delay(10); //debounce the system
          //make servos B and C run for once a day
          //analogWrite(motorPinB, 80);
          for(servoPosB = 0; servoPosB < 90; servoPosB += 1)  // goes from 0 degrees to 180 degrees 
          {                                  // in steps of 1 degree 
            servoB.write(servoPosB);              // tell servo to go to position in variable 'pos' 
            delay(15);                       // waits 15ms for the servo to reach the position 
          } 
          for(servoPosB = 90; servoPosB>=1; servoPosA-=1)     // goes from 180 degrees to 0 degrees 
          {                                
            servoB.write(servoPosB);              // tell servo to go to position in variable 'pos' 
            delay(15); 
          }
          for(servoPosC = 0; servoPosC < 90; servoPosC += 1)  // goes from 0 degrees to 180 degrees 
          {                                  // in steps of 1 degree 
            servoA.write(servoPosC);              // tell servo to go to position in variable 'pos' 
            delay(15);                       // waits 15ms for the servo to reach the position 
          } 
          for(servoPosC = 90; servoPosC>=1; servoPosC-=1)     // goes from 180 degrees to 0 degrees 
          {                                
            servoC.write(servoPosC);              // tell servo to go to position in variable 'pos' 
            delay(15); 
          }
          //delay(300);               Motor A and Motor B may have a need for different speeds, depending on the size and shape of each of the various pills we dispense. Use this code if this is necessary
          //analogWrite(motorPinC, 80);
          delay(50); //how long the motors need to run to spit out exactly one pill of each
        }
        else
        {
          delay(10); //debounce the system
          // leave servos B and C stay off on the even(second) run of servo A, meaning that A gives twice a day while B and C give once a day.
          for(servoPosB = 90; servoPosB>=1; servoPosB-=1)     // goes from 180 degrees to 0 degrees 
          {                                
            servoB.write(servoPosB);              // tell servo to go to position in variable 'pos' 
            delay(15); 
          }
          for(servoPosC = 90; servoPosC>=1; servoPosC-=1)     // goes from 180 degrees to 0 degrees 
          {                                
            servoC.write(servoPosC);              // tell servo to go to position in variable 'pos' 
            delay(15); 
          }
          //analogWrite(motorPinB, LOW); //this is a pill that is given only once a day, motor left off
          //analogWrite(motorPinC, LOW); //this is a pill that is given only once a day, motor left off
        } 
      } 
    }
    days++;
  }

  int myprescriptionfunctionA (int days, int iterations)
  {
    int remainingA;
    remainingA = days - iterations;
    return remainingA;
  } 
  
  int myprescriptionfunctionB (int remainingA)
{
    int remainingB;
    remainingB = remainingA/2;
    return remainingB;
  }
}

Let me rephrase that. You really need to post all your code inside code tags.

sigh. patience is a virtue

It looks to me like "loop()" is incomplete. Get into the habit of typing a closing brace as soon as you type an opening one.

(I am not a virtuous person)

When you add an extra } to the end of the loop function you will find that there is an else without an if error. Too many elses not enough ifs. That is only something you can cure because you ( are supposed ) to know what the code is doing.

Is that what “error: a function-definition is not allowed here before ‘{’ token” means?

//inside the void loop but outside of any of the other loops, these are the functions down here.

Which is NOT where they belong. They go OUTSIDE of loop().

It can mean any number of things caused by a prior slip-up, like here, where the compiler thinks you're trying to define a function inside another function. (this is allowed in some dialects of C, but not this one)

Ok, so the functions need to be outside the loop, so that they do not interfere with other aspects of the code. Let me try that.

Yup, that did it. Thanks.

so the functions need to be outside the loop, so that they do not interfere with other aspects of the code.

Yes, they do, but that’s not why.

Well it compiles now, but how can I change the values of the two functions into numbers which I can print to my LCD? This will be counting down as the program goes on.

T-57: Well it compiles now, but how can I change the values of the two functions into numbers which I can print to my LCD? This will be counting down as the program goes on.

  int myprescriptionfunctionA (int days, int iterations)
  {
    int remainingA;
    remainingA = days - iterations;
    return remainingA;
  }

There is no need to separate the declaration and initialization of the variable. So, this should be:

  int myprescriptionfunctionA (int days, int iterations)
  {
    int remainingA = days - iterations;
    return remainingA;
  }

Since the intermediate variable is not needed, it could be:

  int myprescriptionfunctionA (int days, int iterations)
  {
    return days - iterations;
  }

Which really makes be wonder why you need a function call at all.

By the way, I don't understand your question. Which values do you need to change to numbers (which makes no sense as values ARE numbers)?

the first function counts the times the loop has cycled, corresponding to the twice a day prescription. this number of cycles subtracted from the twice total count of days would indicate the remaining number of medication pills in the hopper.

the second function takes that value and divides it by two, so that we get an accurate count of the once-a-day medications.

I need to take the variables, “remainingA” and “remainingB” and turn them into strings, 40,39,38,37…which will be displayed on the LCD so that the total number of pills left will be displayed.

How do I do that?

I reformatted my functions like you showed, but now it wants me to fix something:

IEP_final_project_iteration_5_01:19: error: 'int remainingA' redeclared as different kind of symbol IEP_final_project_iteration_5_01:8: error: previous declaration of 'int remainingA(int, int)' IEP_final_project_iteration_5_01:20: error: 'int remainingB' redeclared as different kind of symbol IEP_final_project_iteration_5_01:9: error: previous declaration of 'int remainingB(int)'

the first function counts the times the loop has cycled

No, it does. The first function subtracts one number from another.

The second function divides one number by 2.

Hardly the best use of functions.

class LiquidCrystal_I2C : public Print {

The library you are using inherits from the Print class which knows how to convert numbers to strings. Just use lcd.print(someIntegerVariable); to make that happen.

      analogWrite(ledPinGREEN, 1023);

You REALLY ought to hit the reference page for a while.

I reformatted my functions like you showed, but now it wants me to fix something:

Hands on the ouija board . . .

I reformatted my functions

== "I changed my code", but you didn't post it.