## Thursday, 9 March 2017

### Formula based program

Formula #11 (Convert Celsius to Fahrenheit and vice-versa)

(a) Convert Celsius to Fahrenheit (b) Convert Fahrenheit to Celsius
Enter temperature in Fahrenheit: 100.4
Temperature in Celsius: 38

The program for the formula is written in C# programming language and will accept a character as a case selection.
Case B) will help you to Convert Fahrenheit to Celsius. Based on the formula it will find out the output.

 Formula based program

Note: If you are new to C# and Console Application. Try to code First C# Program

Note: Read articles on how to use Loops and Conditions.

Let’s find out a simple and easy way to code these formula.

Practical Implementation:

using System;

namespace patternProblem.Formula
{
{
static void Main(string[] args)
{
Console.Write("(a) Convert Celsius to Fahrenheit (b) Convert Fahrenheit to Celsius \nEnter your selection a/b: ");
double cel = 0.0, far = 0.0; ;

switch (choice)
{
case "a":
Console.Write("Enter temperature in Celsius: ");

far = cel * 9 / 5 + 32;
Console.WriteLine("Temperature in Fahrenheit: " + far);
break;
case "b":
Console.Write("Enter temperature in Fahrenheit: ");

cel = (far - 32) * 5 / 9;
Console.WriteLine("Temperature in Celsius: " + cel);
break;
default:
Console.WriteLine("Invalid ! Selection");
break;
}

}
}
}

Output:
The input case will decide what you want to convert either the Fahrenheit to Celsius or the Celsius to Fahrenheit. So, based on the input case you’ll get the output. The output is shown below:

(a) Convert Celsius to Fahrenheit (b) Convert Fahrenheit to Celsius
Enter temperature in Fahrenheit: 100.4
Temperature in Celsius: 38
Press any key to continue . . .

For any query, comment us below.

Previous – Formulabased program #10

Click imagination hunt to read latest blogs.

Keep learning and sharing...