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:
- 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. - The next line
namespace TemperatureCheck
creates a namespace for the code. - The next line
class Program
defines the class of the code. - The next line
static void Main(string[] args)
is the entry point of the code, which contains the logic of the program. - The next line
Console.WriteLine("Hello Codeauri Family, enter the temperature in centigrade here :");
writes a message asking the user to enter the temperature. - 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 thetemp
variable. - 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.
- 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.