Write a program that converts a temperature given in Celsius to Fahrenheit.
Test the program by performing a compile-time initialization of 32 for the
original Celsius value. Display the original temperature and the formatted
converted value. Go into your source code and change the initialization value
to 0. Rerun the application. Select additional test values and rerun the
application.
Solution:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CelsiusToFahrenheit
{
// Create a class named CelsiusToFahrenheit
class CelsiusToFahrenheit
{
// Create a main method to run the program
static void Main(string[] args)
{
// Declare a double variable named celsius to store the celsius value.
double celsius = 32;
// Declare a double variable named fahrenheit to store the fahrenheit value.
double fahrenheit;
//logical formula for convertion from celsius to fahrenheit
//fahrenheit=((celsius*9)/5)+32;
fahrenheit = ((celsius * 9)/ 5) + 32; //convertion from celsius to fahrenheit
//display celsius value up to two decimal places
Console.WriteLine("Delared Celsius Value : " + "{0:f2}", +celsius);
//display fahrenheit value up to two decimal places
Console.WriteLine("Convertred Fahrenheit Value : " + "{0:f2}", +fahrenheit);
}
}
}
Output 1:
Delared Celsius Value : 32.00
Convertred Fahrenheit Value : 89.60
Output 2:
Delared Celsius Value : 0.00
Convertred Fahrenheit Value : 32.00