Quote:
Originally Posted by Arevos
Well, I'll give you an example similar to your problem. Lets say you want to create a program that converts Fahrenheit into degrees Celsius. It might look something like this:
using System; namespace Example { class FahrenheitCelsiusConverter { static void Main(string[] args) { // Get input from the user Console.WriteLine("Enter a temperature in Fahrenheit"); string userInput = Console.ReadLine(); // Convert user input into a number double fahrenheit; try { fahrenheit = double.Parse(userInput); } // If the user entered something that wasn't a number // then complain and exit catch (FormatException) { Console.WriteLine("Invalid input. Exiting!"); return; } // Convert fahrenheit to celsius using an equation double celsius = (fahrenheit - 32) / 1.8; Console.WriteLine("The temperature in Celsius is " + celsius); } } }
Note that "double" is a type of number in C# that can have decimal places. If you only need whole numbers (i.e. integers), then you can use "int" instead.
|
Arevos
ill have a go at changing the bits necessary for me