# Converting distance to feet' inches''

Hey guys ive hit a brick wall atm, I've managed to convert my distance from the sonar sensor to Ft,M,Cm and In. im trying to join the ft and inches so it reads, example ( 6' 2") . I've looked around but havent figured it out yet.

Here is my code so far. new at this so let me know what is wrong and should be changed.

p.s im not sure how else to post the script other than past it here. thanks in advance.

#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
///lcd i2c bus (A4,A5)

#define echoPin 11 // Echo Pin
#define trigPin 12 // Trigger Pin
#define LEDPin 13 // Onboard LED

long duration, centimeters, inches, feet, metre; // distance=cms, distent=inches

void setup() {

Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LEDPin, OUTPUT); // Use LED indicator (if required)

lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();

}

void loop() {

// Delay 50ms before next reading.
delay(150);

/* The following trigPin/echoPin cycle is used to determine the
distance of the nearest object by bouncing soundwaves off of it. */
digitalWrite(trigPin, LOW);
delayMicroseconds(100);

digitalWrite(trigPin, HIGH);
delayMicroseconds(100);

digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);

//Calculate the distance (in cm) based on the speed of sound.
float centimeters = duration/58.2;//cms
float inches = duration/148;//inchs
float feet = inches/12;
float metre = centimeters/100;
// display on lcd

String cm = String(centimeters);//cms
String in = String(inches);//inchs

lcd.clear();

//inches
lcd.setCursor(8, 0);
lcd.print(in); // first line
lcd.print(" In");

//cms
// lcd.setCursor(0, 1);
// lcd.print(cm); // second line
// lcd.print(" cm");

//feet
lcd.setCursor(0, 0);
lcd.print(feet);
lcd.print(" ft");

//metres
lcd.setCursor(0, 1);
lcd.print(metre);
lcd.print(" M");

}

Explore what division and modulo can do for you

Careful on using floating point and rounding etc.

Why do you convert inches to a String, but not feet?
Why even bother with String here?