Basic Programming C# Examples

C# Program to read Temperature in Centigrade & Display Suitable Message

The Program in C# Program to read Temperature in Centigrade & Display Suitable Message is below:

using System;

namespace TemperatureCheck
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello Codeauri Family, enter the temperature in centigrade here :");
            float temp = Convert.ToSingle(Console.ReadLine());

            if (temp < 0)
            {
                Console.WriteLine("Hmm, its Freezing weather");
            }
            else if (temp >= 0 && temp <= 10)
            {
                Console.WriteLine("Very Cold weather");
            }
            else if (temp > 10 && temp <= 20)
            {
                Console.WriteLine("Cold weather");
            }
            else if (temp > 20 && temp <= 30)
            {
                Console.WriteLine("Normal in temperature");
            }
            else if (temp > 30 && temp <= 40)
            {
                Console.WriteLine("It's hot");
            }
            else
            {
                Console.WriteLine("OHH! It's very hot");
            }
        }
    }
}

Output:

Hello Codeauri Family, enter the temperature in centigrade here :
99
OHH! It’s very hot

Pro-Tips💡

Here are the step by step execution of above program:

  1. The first line of the code using System; is an instruction to import the System namespace, which includes the Console class used for input/output operations.
  2. The next line namespace TemperatureCheck creates a namespace for the code.
  3. The next line class Program defines the class of the code.
  4. The next line static void Main(string[] args) is the entry point of the code, which contains the logic of the program.
  5. The next line Console.WriteLine("Hello Codeauri Family, enter the temperature in centigrade here :"); writes a message asking the user to enter the temperature.
  6. The next line float temp = Convert.ToSingle(Console.ReadLine()); reads the temperature entered by the user, converts it to a single-precision floating-point number and stores it in the temp variable.
  7. The next block of code is an if-else statement that checks the temperature entered by the user and displays a message indicating the weather based on the temperature value.
  8. The code ends with a closing brace for the Main method, the Program class and the TemperatureCheck namespace.

Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

Programming Languages( Types, Pros and Cons)-Codeauri

What are the types or levels of Programming Languages? The types or levels of programming languages are divided into two types: Types Of Programming Languages: 1.Machine-level Language :1st…

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X