Formula based program

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

(a) Convert Celsius to Fahrenheit (b) Convert Fahrenheit to Celsius
Enter your selection a/b: b
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 A) will help you to Convert Celsius to Fahrenheit.
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
{
    class Formula11     //find student grade
    {
        static void Main(string[] args)
        {
            Console.Write("(a) Convert Celsius to Fahrenheit (b) Convert Fahrenheit to Celsius \nEnter your selection a/b: ");
            string choice = Console.ReadLine().ToLower();
            double cel = 0.0, far = 0.0; ;
           
            switch (choice)
            {
                case "a":
                    Console.Write("Enter temperature in Celsius: ");
                    cel = Convert.ToDouble(Console.ReadLine());

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

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

            Console.ReadKey();
        }
    }
}

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 your selection a/b: b
Enter temperature in Fahrenheit: 100.4
Temperature in Celsius: 38
Press any key to continue . . .


For any query, comment us below.

Skip to Main Table – Formula based program

Previous – Formulabased program #10


Click imagination hunt to read latest blogs.


Keep learning and sharing...

Comments

Popular posts from this blog

SSC CGL 2016 Tier-1 Marks / Result

DATA TYPES IN C#

Pattern printing program

IS STRING MUTABLE OR IMMUTABLE IN .NET?

Top Mutual Funds

SSC CGL 2017 TIER 2 RESULT OUT

JUST IN TIME (JIT)

Can we have multiple Main methods in one class

TOP 15 VISUAL STUDIO SHORTCUT KEYS

Top 10 Interview Tips and Questions