In: Computer Science
Write code to ask user to provide input length in miles, yards, feet and inches and write code to convert sum of total length into meters. Display result by reiterating input values in inches, feet, yards, and miles entered by user, and the sum of the total length in meters. PLEASE use bluej for code
Since you have not mentioned the language of your preference, I am providing the code in JAVA.
CODE
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(true) {
double miles, yards, feet, inches;
System.out.println("Enter the length in miles: ");
miles = sc.nextDouble();
System.out.println("Enter the length in yards: ");
yards = sc.nextDouble();
System.out.println("Enter the length in feet: ");
feet = sc.nextDouble();
System.out.println("Enter the length in inches: ");
inches = sc.nextDouble();
double meters = 1609.34 * miles + 0.9143977272588 * yards + 0.30479924241959999165 * feet + 0.025399936868299999304 * inches;
System.out.println("Sum of length in meters = " + meters);
char cont;
System.out.println("Do you wish to continue (Y/N) : ");
cont = sc.next().charAt(0);
if (cont != 'Y' && cont != 'y') {
break;
}
}
}
}