SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Barbara Dolye
Chapter:
Data Types And Expressions
Exercise:
Programming Exercises
Question:1 | ISBN:9781285096261 | Edition: 4

Question

Design an application that converts miles to feet. Declare and initialize miles to 4.5. Show your miles formatted with two positions to the right of the decimal. Feet and inches should both be shown with no positions to the right of the decimal. Once you get that portion running, modify your solution so that you also show the total number of inches. Go into your source code and change the initialization value for miles. Rerun the application.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Solution :
 

/* Author: Sudhakar 
   Date: 13/04/2020
   Task: Miles to Feet and Inches */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProExercise1
{
    class Program
    {
        static void Main(string[] args)
        {
            //declaration
            double milesLength = 4.5;
            double feetLegth;
            double inchesLength;
            feetLegth = milesLength * 5280;  //convertion from miles to feet
            inchesLength = milesLength * 5280 * 12;  //convertion from miles to inches
            //display output
            Console.WriteLine("Given Miles : " + "{0:f2}", +milesLength);
            Console.WriteLine("Length from Miles to Feet : " + "{0:f0}", +feetLegth);
            Console.WriteLine("Length from Miles to Inches : " + "{0:f0}", +inchesLength);
         
        }
    }
}

 

Output :

Given Miles : 4.50
Length from Miles to Feet : 23760
Length from Miles to Inches : 285120

0 0

Discussions

Post the discussion to improve the above solution.