A C# program that convertes inches to meters

In the follow lines it is presented an example of code which This program converts the meters to inches.It is based the book C# 3.0 (Herbert Schildt).Chapter 1 Exercise 12.All you have to do is to is to run it as console application in Visual Studio.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
//This program converts the meters to inches.It is based the book C# 3.0 (Herbert Schildt).Chapter 1 Exercise 12
//
class Program
{
static void Main(string[] args)
{
int counter = 0;
double inches=1.0;
double meters;
for (inches = 1.0; inches <= 144.0; inches++)
{
meters = inches / 39.37;
if (inches == 1)
Console.WriteLine(inches + “inch is equal to” + meters + “meters”);//It has been writen fo the first inch
if (inches != 1)
Console.WriteLine(inches + “inches is equal to” + meters + “meters”);
counter++;
}
if (counter == 12) {

Console.WriteLine(“——————————————————————————————“);
counter = 0; //Reset counter to zero

}
}
}
}

Advertisements