I'm two months in a programming course and our instructor told us we should think about building real-world applications as to gain valuable experience. I got the idea of doing a simple temperature conversion app.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TempratureProject
{
class Program
{
static void Main(string[] args)
{
//Ask for the temprature that the user wants to convert
Console.WriteLine("What is the temprature you wish to convert?");
var RInput = Console.ReadLine();
double dInput = Convert.ToDouble(RInput);
//Ask for what type of conversion
Console.WriteLine("If you wish to convert Fahrenheit to Celsius, Press 1");
Console.WriteLine("If you wish to convert Fahrenheit to Kelvin, Press 2");
Console.WriteLine("If you wish to convert Celsius to Fahrenheit, Press 3");
Console.WriteLine("If you wish to convert Celsius to Kelvin, Press 4");
Console.WriteLine("If you wish to convert Kelvin to Fahrenheit, Press 5");
Console.WriteLine("If you wish to convert Kelvin to Celsius, Press 6");
//Set YInput equal to the choice made
var YInput = Console.ReadLine();
int iInput = Convert.ToInt32(YInput);
//Use of a a series of If statements to call the methods
if (iInput == 1)
{
var aAnswer = FtoCelsius(dInput);
Console.WriteLine("The value of {0} degrees Fahrenheit is equall to {1} degrees Celsius", dInput, aAnswer);
}
else if (iInput == 2)
{
var bAnswer = FtoKelvin(dInput);
Console.WriteLine("The value of {0} degrees Fahrenheit is equall to {1} degrees Kelvin", dInput, bAnswer);
}
else if (iInput == 3)
{
var cAnswer = CtoFahenreit(dInput);
Console.WriteLine("The value of {0} degrees celcius is equall to {1} degrees Fahrenheit", dInput, cAnswer);
}
else if (iInput == 4)
{
var dAnswer = CtoKelvin(dInput);
Console.WriteLine("The value of {0} degrees celsius is equall to {1} degrees Kelvin", dInput, dAnswer);
}
else if (iInput == 5)
{
var eAnswer = KtoFahrenheit(dInput);
Console.WriteLine("The value of {0} degrees Kelvin is equall to {1} degrees Fahrenheit", dInput, eAnswer);
}
else
{
var fAnswer = KtoCelsius(dInput);
Console.WriteLine("The Value of {0} degrees Kelvin is equall to {1} degrees Celsius", dInput, fAnswer);
}
}
//The various methods
static double FtoKelvin(double CTempIn)
{
double fKel = (CTempIn - 32) * (5 / 9) + 273.15;
return fKel;
}
static double FtoCelsius(double CTempIn)
{
Double fCels = (CTempIn - 32) * (5 / 9);
return fCels;
}
static double CtoFahenreit(double CtempIn)
{
double dFahr = (1.8) * (CtempIn + 32);
return dFahr;
}
static double CtoKelvin(double CTempIn)
{
double cKel = CTempIn + 273.15;
return cKel;
}
static double KtoFahrenheit(double CTempIn)
{
double kFah = (CTempIn - 273.15) * (9 / 5) + 32;
return kFah;
}
static double KtoCelsius(double CTempIn)
{
double KCel = CTempIn - 273.15;
return KCel;
}
}
}
It is working so there is that but I would like to know how well this is written and how I could make it better.