Applied Programming/Variables/C Sharp

variables.cs edit

/// <summary>
/// This program converts a Fahrenheit temperature to Celsius.
/// </summary>
/// <remarks>
/// Input:
///     Fahrenheit temperature
/// 
/// Output:
///     Fahrenheit temperature
///     Celsius temperature
/// 
/// Example:
///     Enter Fahrenheit temperature:
///      100
///     100.0 degrees Fahrenheit is 37.8 degrees Celsius
/// 
/// TODO:
///     * Functions will be added in a future release.
/// 
/// References:
///     * http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html
///     * http://www.mathsisfun.com/temperature-conversion.html
///     * https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/xmldoc/how-to-use-the-xml-documentation-features
///     * https://blog.rsuter.com/best-practices-for-writing-xml-documentation-phrases-in-c/
///     * https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/how-to-define-constants
/// </summary>

using System;

/// <summary>Provides constants for the program.</summary>
static class Constants
{
    public const int TemperatureDifference = 32;
    public const double TemperatureRatio = 5.0 / 9;
}

/// <summary>Provides the main program code.</summary>
class Program 
{
    /// <summary>Runs the main program.</summary>
    public static void Main (string[] args) 
    {
        Console.WriteLine("Enter Fahrenheit temperature:");
        var fahrenheit = Convert.ToDouble(Console.ReadLine());

        var celsius = (fahrenheit - Constants.TemperatureDifference) * 
                Constants.TemperatureRatio;

        Console.WriteLine(String.Format(
            "{0:f1} degrees Fahrenheit is {1:f1} degrees Celsius",
            fahrenheit,
            celsius));
    }
}

Try It edit

Copy and paste the code above into one of the following free online development environments or use your own C Sharp compiler / interpreter / IDE.

See Also edit