How can I create a console-based application whose Main() method
holds an integer variable named inches, and prompt
the user for a value. and to create a method to which I pass
inches. The method converts the value to feet and inches
and displays the result. For example, 67 inches is 5 feet 7
inches. ?
VulpesPosted Sep 10, 2014, 6:52 AM
VulpesPosted Sep 14, 2014, 10:50 AM
// add 'skeleton' handler by double-clicking button in VS designer
lovlly bersbePosted Sep 12, 2014, 11:29 PM
VulpesPosted Sep 10, 2014, 12:38 PM
using System;
class Program
{
static void Main()
{
Console.Write("Enter number of inches : ");
int inches = int.Parse(Console.ReadLine());
InchesToFeet(inches);
InchesToYards(inches);
Console.ReadKey();
}
static void InchesToFeet(int inches)
{
int feet = inches / 12;
int inches2 = inches % 12;
string inchStr = (inches == 1) ? "inch" :"inches";
string footStr = (feet == 1) ? "foot" : "feet";
string inchStr2 = (inches2 == 1) ? "inch" :"inches";
Console.WriteLine("{0} {1} is {2} {3} {4} {5}", inches, inchStr, feet, footStr, inches2, inchStr2);
}
static void InchesToYards(int inches)
{
int feet = inches / 12;
int inches2 = inches % 12;
int yards = feet / 3;
feet = feet % 3;
string inchStr = (inches == 1) ? "inch" :"inches";
string footStr = (feet == 1) ? "foot" : "feet";
string inchStr2 = (inches2 == 1) ? "inch" :"inches";
string yardStr = (yards == 1) ? "yard" : "yards";
Console.WriteLine("{0} {1} is {2} {3} {4} {5} {6} {7}", inches, inchStr, yards, yardStr, feet, footStr, inches2, inchStr2);
}
}
lovlly bersbePosted Sep 10, 2014, 12:25 PM
Abhishek KumarPosted Sep 10, 2014, 6:32 AM
Please find the sample code attached.
Hope this will help you.
Abhishek
Dipankar BiswasPosted Sep 10, 2014, 5:16 AM
using System.Collections.Generic;
using System.Text;
class Utilities
{
public string ConvertMetersToFeet(string strMeters)
{
double feet = 0;
double meters = 0;
if (double.TryParse(strMeters, out meters))
feet = meters * 3.2808399;
return feet.ToString();
}
}
http://www.java2s.com/Code/CSharp/Development-Class/ConvertMetersToInches.htm
lovlly bersbePosted Sep 10, 2014, 3:58 AM
Dipankar BiswasPosted Sep 10, 2014, 3:34 AM