Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

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 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...

No comments:

Post a Comment

Featured post

Think that makes you rich and richer

 Napolean said: “You can think and grow rich, but if you can be brought up like most people with work and you won't starve, this wil...