BWD code won't lcd print second var.

Due to insufficient info on my previous problem, and since i'm pretty new in this,i redo my code with BWD in mind. This is my first try.
The basic setup is 2 sonar distance sensors.Everything is set correctly hardware wise(either way with delay() style code everything works fine) and in Serial.Print I'm able to see the distance of both sensors as they calculate.My issue is that only FRsensor prints in lcd while RRsensor stays 0.0

//code is a snippet only!
unsigned long frmillis;
unsigned long rrmillis;
unsigned long cmillis;
unsigned long printmillis;

int lblink_p = 50;
int frsensor_p = 10; //read period frsensor
int rrsensor_p = 20; //read period rrsensor
int button_p = 50; 
int print_p = 5000; //print period


void setup() {
  frmillis = millis();
  rrmillis = millis();
  printmillis = millis();
  pinMode(FRtrigPin, OUTPUT); 
  pinMode(FRechoPin, INPUT); 
  pinMode(RRtrigPin, OUTPUT); 
  pinMode(RRechoPin, INPUT); 
}








void loop() {
  cmillis = millis();
  if (cmillis - rrmillis >= rrsensor_p) {
    digitalWrite(RRtrigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(RRtrigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(RRtrigPin, LOW);
    RRduration = pulseIn(RRechoPin, HIGH);
    float RRdistance =   RRduration * 0.034 / 2;
    rrmillis = cmillis;
//in serial.print here gives correct distance!


  }

  if (cmillis - frmillis >= frsensor_p) {
    digitalWrite(FRtrigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(FRtrigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(FRtrigPin, LOW);
    FRduration = pulseIn(FRechoPin, HIGH);
    FRdistance =  FRduration * 0.034 / 2;
    frmillis = cmillis;
  }

  if (cmillis - printmillis >= print_p) {
    lcd.setCursor(9, 1);
    lcd.print(RRdistance, 1);
//In Serial.print here it goes 0,0
    lcd.setCursor(9, 0);
    lcd.print(FRdistance, 1);
    printmillis = cmillis;
  }

}

That program won' t compile. Please post one that will.

// include the library code:
#include <LiquidCrystal.h>
#include <EEPROM.h>
LiquidCrystal lcd(7, 8, 3, 4, 5, 6);
const int FRtrigPin = 15;
const int FRechoPin = 14;
const int RRtrigPin = 16;
const int RRechoPin = 17;
const int ledpinB = 11;
const int ledpinR = 10;
const int ledpinY = 9;

unsigned long frmillis;
unsigned long rrmillis;
unsigned long cmillis;
unsigned long printmillis;
int lblink_p = 50;
int frsensor_p = 10;
int rrsensor_p = 20;
int button_p = 50;
int print_p = 5000;







float FRduration;
float FRdistance;
float FRdistance1;
float RRdistance1;
float RRduration;
float RRdistance;
float initFR;
float initRR;
float FRperc;
float RRperc;
unsigned long fr;




byte g1[] = {
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B11000,
  B11000,
  B11000
};

byte g2[] = {
  B11111,
  B11111,
  B11111,
  B11111,
  B11111,
  B00000,
  B00000,
  B00000
};

byte g3[] = {
  B11000,
  B11000,
  B11011,
  B11001,
  B11001,
  B11001,
  B11001,
  B11111
};

byte l[] = {
  B11000,
  B00000,
  B11000,
  B11000,
  B11000,
  B11000,
  B11000,
  B11111
};

byte o[] = {
  B11111,
  B00000,
  B11001,
  B11001,
  B11001,
  B11001,
  B11001,
  B11111
};

byte g[] = {
  B11111,
  B00000,
  B11000,
  B11011,
  B11001,
  B11001,
  B11001,
  B11111
};

byte i[] = {
  B10111,
  B00000,
  B10111,
  B10111,
  B10111,
  B10111,
  B10111,
  B10111
};

byte c[] = {
  B11111,
  B00000,
  B11000,
  B11000,
  B11000,
  B11000,
  B11000,
  B11111
};




void setup() {
  Serial.begin(9600); // Starts the serial communication
  for (int i = 0 ; i < EEPROM.length() ; i++)
  {
    EEPROM.write(i, 0);
  }

  frmillis = millis();
  rrmillis = millis();
  printmillis = millis();




  lcd.begin(16, 2);
  lcd.createChar(0, g1);
  lcd.createChar(1, g2);
  lcd.createChar(2, g3);
  lcd.createChar(3, l);
  lcd.createChar(4, o);
  lcd.createChar(5, g);
  lcd.createChar(6, i);
  lcd.createChar(7, c);
  lcd.home();
  lcd.setCursor(0, 0);
  lcd.write(byte(0));
  delay(50);
  lcd.setCursor(0, 1);
  lcd.write(byte(2));
  delay(50);
  lcd.setCursor(1, 1);
  lcd.write(byte(3));
  delay(50);
  lcd.setCursor(2, 1);
  lcd.write(byte(4));
  delay(50);
  lcd.setCursor(3, 1);
  lcd.write(byte(5));
  delay(50);
  lcd.setCursor(4, 1);
  lcd.write(byte(6));
  delay(50);
  lcd.setCursor(5, 1);
  lcd.write(byte(7));
  delay(400);
  lcd.clear() ;
  lcd.setCursor(0, 1);
  lcd.print("tR:");
  lcd.setCursor(6, 1);
  lcd.print("dR:");
  lcd.setCursor(0, 0);
  lcd.print("tF:");
  lcd.setCursor(6, 0);
  lcd.print("dF:");
  pinMode(2, INPUT);
  pinMode(FRtrigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(FRechoPin, INPUT); // Sets the echoPin as an Input
  pinMode(RRtrigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(RRechoPin, INPUT); // Sets the echoPin as an Input


}






void loop() {
  cmillis = millis();
  if (cmillis - rrmillis >= rrsensor_p) {
    digitalWrite(RRtrigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(RRtrigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(RRtrigPin, LOW);
    RRduration = pulseIn(RRechoPin, HIGH);
    float RRdistance =   RRduration * 0.034 / 2;
    rrmillis = cmillis;
  }

  if (cmillis - frmillis >= frsensor_p) {
    digitalWrite(FRtrigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(FRtrigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(FRtrigPin, LOW);
    FRduration = pulseIn(FRechoPin, HIGH);
    FRdistance =  FRduration * 0.034 / 2;
    frmillis = cmillis;
  }



  if (cmillis - printmillis >= print_p) {
    lcd.setCursor(9, 1);
    lcd.print(RRdistance, 1);
    lcd.setCursor(9, 0);
    lcd.print(FRdistance, 1);
    printmillis = cmillis;
  }

}

Drop the 'float' declaration from here

    float RRdistance =   RRduration * 0.034 / 2;

make it

    RRdistance =   RRduration * 0.034 / 2;

and move it here where you declared the other one:

float FRduration;

aarg:
Drop the 'float' declaration from here

    float RRdistance =   RRduration * 0.034 / 2;

make it

    RRdistance =   RRduration * 0.034 / 2;

and move it here where you declared the other one:

float FRduration;

Ok it works,
But why?
I mean it has already been declared in the start,so a second declaration messes smth up?

You’ve declared a new local variable RRdistance...

float RRdistance =   RRduration * 0.034 / 2;

This overrides the scope of the global RRdistance.

Never declare local variables with the same name as globals. It’s the programming equivalent of calling both your children “Bob” and then wondering why you get confused about which one you are talking about.

This is a variable declaration...
float RRdistance;...it declares a new instance of a variable RRdistance that replaces any previous instance of a the variable with the same name. It doesn’t assign it a value.

This is a variable assignment...
RRdistance = RRduration * 0.034 / 2;...it assigns the previously declared variable RRdistance the specified value.

This is a shorthand for a variable declaration AND assignment all in one go...

float RRdistance = RRduration * 0.034 / 2;

Usually if you have more than one variable declaration of a variable with the same name you are heading for a fall because you’ll forget when one of them falls “out of scope”, at which point it is replaced by the previously declared one.

Edit: The “scope” of a variable is defined by its enclosing { } code block.