4. Converting distance values (25 pts) Write a program that converts distance va
ID: 3699090 • Letter: 4
Question
4. Converting distance values (25 pts) Write a program that converts distance values. The program should give the user three options: convert a whole number of inches to feet and inches, convert feet and inches to decimal feet, or feet and inches to inches. Write the decimal feet to three decimal places. For example, 80 inches is 6 feet, 8 inches; 5 fect, 6 inches is 5.5 feet, and 4 feet, 2 inches is 50 inches. An example of output is provided below: hat would you like to do? Convert whole nunber of inches to feet and inches Convert feet and inches to decinal feet Convert feet and inches to inches 4. Exit nter 1. 2. 3. or 4 nter total inches (such as 6 88 8 inches is equal to 6 Feet 8 inches t would you like to do? Convert whole nunber of inches to feet and inches Convert feet and inches to decinal Feet Convert feet and inches to inches ha ? Exit nter 1. 2. 3. or The program will be named using your name, such as "JohnSmith 4.cppExplanation / Answer
Hi friend, you have not mentioned about Programing language.
I have implemented in C#:
C# code follows
--------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class conversion
{
public static string inchesValue, feetValue;
static void Main(string[] args)
{
Console.WriteLine(" Chapter 3 - Problem 41");
Console.WriteLine("");
mainMenu();
}
public static void mainMenu()
{
Console.WriteLine("What would you like to do? ");
Console.WriteLine("1.Convert the whole number of inches to feet and inches");
Console.WriteLine("2.Convert feet and inches to decimal feet.");
Console.WriteLine("3.Convert feet and inches to inches.");
Console.WriteLine("4.Exit.");
Console.WriteLine("");
Console.Write("Enter 1,2,3 or 4 --> ");
string userChoice = Console.ReadLine();
switch (userChoice)
{
case "1":
Console.Write("Enter total inches(such as 60)--> ");
inchesValue = Console.ReadLine();
int feetResultValue1 = Convert.ToInt32(inchesValue) / 12;
int inchesLeftResultValue = Convert.ToInt32(inchesValue) % 12;
Console.WriteLine("{0} inches is equal to {1} Feet and {2} Inches", inchesValue, feetResultValue1, inchesLeftResultValue);
Console.WriteLine("");
mainMenu();
return;
case "2":
Console.Write("Enter feet --> ");
feetValue = Console.ReadLine();
Console.Write("Enter inches --> ");
inchesValue = Console.ReadLine();
decimal feetResultValue2 = Convert.ToDecimal(feetValue) + (Convert.ToDecimal(inchesValue) / 12);
Console.WriteLine("{0} feet and {1} inches is equal to {2} feet ",feetValue,inchesValue, feetResultValue2);
Console.WriteLine("");
mainMenu();
return;
case "3":
Console.Write("Enter feet --> ");
feetValue = Console.ReadLine();
Console.Write("Enter inches --> ");
inchesValue = Console.ReadLine();
Console.WriteLine("");
decimal feetResultValue3 = (Convert.ToInt32(feetValue)*12) + Convert.ToInt32(inchesValue) ;
Console.WriteLine("{0} feet and {1} inches is equal to {2} inches ", feetValue, inchesValue, feetResultValue3);
Console.WriteLine("");
mainMenu();
return;
case "4":
Environment.Exit(0);
break;
default:
Console.WriteLine("Wrong entry !!!!");
Console.WriteLine("");
mainMenu();
break;
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.