dimanche 4 octobre 2015

Trouble with converting Fahrenheit to Celsius. C# [duplicate]

This question already has an answer here:

I am struggling to get my program to actually do the maths bit in order to convert Fahrenheit to Celsius and vice verse, no matter what I input I don't get the right conversions. here is the code =

  int option;
            Single  farenheit, celsius, farConverted, celConverted;



            do // Do loop to allow the user to exit from the main menu
            {

                Console.WriteLine("**************Main Menu****************");
                Console.WriteLine("What do you want to do? Enter the number");
                Console.WriteLine("1) Fahrenheit to Celsius");
                Console.WriteLine("2) Celsius to Fahrenheit");
                Console.WriteLine("3) Exit");
                option = Convert.ToInt16(Console.ReadLine());

                if (option == 1) //If loop which activate based on the option selected
                {

                    Console.Clear();

                    Console.WriteLine("Enter the Fahrenheit value");
                    farenheit = Convert.ToSingle(Console.ReadLine());

                    //The maths bit
                    celConverted = (farenheit - 32)*(5 / 9);
                    Convert.ToSingle(celConverted);

                    Console.WriteLine("The conversion to celsius is:- " + celConverted + "°C");
                    Console.WriteLine("Press <Enter> to go back to the main menu");
                    Console.ReadLine();
                    Console.Clear();
                }

                else if (option == 2) 
                {

                    Console.Clear();

                    Console.WriteLine("Enter the celsius value");
                    celsius = Convert.ToSingle(Console.ReadLine());

                    //The maths bit
                    farConverted = celsius * (9 / 5) + 32;
                    Convert.ToSingle(farConverted);

                    Console.WriteLine("The conversion to Fahrenheit is:- " + farConverted + "°F");
                    Console.WriteLine("Press <Enter> to go back to the main menu");
                    Console.ReadLine();
                    Console.Clear();
                }



            } while (option != 3);

I am MS Visual studio isn't pin pointing out any specific errors with the code itself so I am not sure what is wrong.

Thanks for reading.

Aucun commentaire:

Enregistrer un commentaire