Loop inside void loop()

I'm currently working with a school project. What I need is to jump back to the 1-peso coin selection when the value of the inserted bill is not equal to the total of the selected 1-peso, 5-peso and 10-peso coins. I'm stuck here for a week now and I still don't know how to do this.

Here is my code.

#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <Servo.h>


# define BOUNCE_DURATION 30;    //20 ms
volatile unsigned long bouncetime = 0;
int money = 0;
const byte interruptPin=2;

LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);//RS,EN,D4,D5,D6,D7

const byte Rows= 4; //number of rows on the keypad i.e. 4
const byte Cols= 3; //number of columns on the keypad i,e, 3

//we will definne the key map as on the key pad:

char keymap[Rows][Cols]={
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};

byte rPins[Rows]= {3,4,5,6}; //Rows 0 to 3
byte cPins[Cols]= {7,8,9}; //Columns 0 to 2

Keypad kpd= Keypad(makeKeymap(keymap), rPins, cPins, Rows, Cols);



int onepeso = 300;
int fivepeso = 300;
int tenpeso = 300;

Servo servoOne;
Servo servoFive;
Servo servoTen;

String sharp="";
int piso=0;
int lima=0;
int sampu=0;

String input="";
String remlast = "";

int total=0;

void setup() {
lcd.begin(20,4);
servoOne.attach(10);
servoFive.attach(11);
servoTen.attach(12);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt (0, bill_value, CHANGE);
start_screen();

}
void loop() {
char key2 = kpd.getKey();


  if (key2 != NO_KEY)
     { 
       lcd.print(key2);

       if (sharp == "")
       {
          input+=key2;
          remlast = input;
          remlast.replace("*","");
            remlast.replace("#","");
            piso = remlast.toInt();
       }
       else if (sharp == "five")
       {
          input+=key2;
          remlast = input;
          remlast.replace("*","");
            remlast.replace("#","");
            lima = remlast.toInt();
       }
       else if (sharp == "ten")
       {
          input+=key2;
          remlast = input;
          remlast.replace("*","");
            remlast.replace("#","");
            sampu = remlast.toInt();
       }

      if(key2=='*' && sharp!=NULL)
      {
        lcd.rightToLeft();
        sharp="";
        piso=0;
        lima=0;
        sampu=0;
        input="";
        remlast="";
      }  

      if (sharp=="ten" && key2=='#')
      {
        total=((piso*1)+(lima*5)+(sampu*10));
        if (total==money)
        {
          sharp = "out";
          lcd.clear();
          lcd.print("Please wait.");
          lcd.setCursor(0,1);
          lcd.print("Dispensing coins.");
          servoPiso();
          servoLima();
          servoSampu();
        }
        else()
        {
          lcd.clear();
          lcd.print("Sorry!Coins selected");
          lcd.setCursor(0,1);
          lcd.print(" and bill value not ");
          lcd.setCursor(0,2);
          lcd.print("equal.");
          //insert code here to loop from the start
        }

      }

     else if (sharp=="five" && key2=='#')
       {
          lcd.clear();
          lcd.print("10-peso=");
          lcd.setCursor(0,1);
          lcd.print("(*)Erase  (#)Enter");
          lcd.setCursor(8,0);  
          sharp="ten";  
          input = 0;      
       }

     else if (key2=='#')
      {
        lcd.clear();
        lcd.print("5-peso=");
        lcd.setCursor(0,1);
        lcd.print("(*)Erase  (#)Enter");
        lcd.setCursor(7,0); 
        sharp="five";
        input = 0;

      }
      if (key2=='*')
      {
        lcd.clear();
        lcd.print("1-peso=");
        lcd.setCursor(0,1);
        lcd.print("(*)Erase  (#)Enter");
        lcd.setCursor(7,0); 
      }

      }
   }
//--------------------READS BILL VALUE--------------------//
void bill_value(){
  if(millis() > bouncetime){
    if(!digitalRead(2)){
      money=money +10;  
    // lcd.print(money);   
    displayLCD(); 
    }   
    bouncetime = millis() + BOUNCE_DURATION;
  }

} 


//--------------------DISPLAY LCD--------------------//
void displayLCD()
{

  lcd.clear();
  lcd.print("You inserted Php");
  lcd.print(money);
  lcd.setCursor(0,1);
  lcd.print("Coins: ");  
  lcd.print(" 1Peso:");
  lcd.print(onepeso);
  lcd.setCursor(0,2);
  lcd.print("5Peso:");
  lcd.print(fivepeso);
  lcd.print("10Peso:");
  lcd.print(tenpeso);
  lcd.setCursor(0,3);
  lcd.print("Press * to continue"); 
} 

//--------------------START SCREEN--------------------//
void start_screen()
{
  lcd.print("********************");
  lcd.setCursor(0,1);
  lcd.print("    BILL O' COIN    ");
  lcd.setCursor(0,2);
  lcd.print("  [ INSERT  BILL ]  ");
  lcd.setCursor(0,3);  
  lcd.print("********************");
  delay (2000);
} //end of start_screen

//--------------------SERVO FOR ONE--------------------//
void servoPiso()
{
  servoOne.write(70);
  delay(10);
    int x = piso;
    while(x>0)
    {
      servoOne.write(170);
      delay(200);
      servoOne.write(40);
      delay(200);
      x--;
    }
}

//--------------------SERVO FOR FIVE--------------------//
void servoLima()
{
  servoFive.write(70);
  delay(10);
    int x = lima;
    while(x>0)
    {
      servoFive.write(170);
      delay(200);
      servoFive.write(40);
      delay(200);
      x--;
    }
}

//--------------------SERVO FOR TEN--------------------//
void servoSampu()
{
  servoTen.write(70);
  delay(10);
    int x = sampu;
    while(x>0)
    {
      servoTen.write(170);
      delay(200);
      servoTen.write(40);
      delay(200);
      x--;
    }
}

Please help me out. Thanks.

Can you please explain what the program is expected to do.

Oh, and you can't check strings for equality like that. You'd be better off using an enum or just some #defined numbers for sharp.

First, using the String (note uppercase 'S') class is going to bloat your code much more than if you use regular char arrays. Second, you can always find string (note lowercase 's') replacements for all of the String class functionality. For example, your statement:

  • else if (sharp == "five")*
    could be rewritten for a character array as:

  • else if (strcmp(sharp, "five") == 0)*

You can find a summary list of the str?() functions here.

If the total value of the selected 1-peso, 5-peso and 10-peso coins is not equal to the value of the bill inserted, the program should start again from lcd.print("1-peso=");

UKHeliBob:
Can you please explain what the program is expected to do.