Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp exercises: Accept a temperature in centigrade and display a suitable message


C# Sharp Conditional Statement : Exercise-13 with Solution

Write a C# Sharp program to read temperature in centigrade and display suitable message according to temperature.

Temp < 0 then Freezing weather
Temp 0-10 then Very Cold weather
Temp 10-20 then Cold weather
Temp 20-30 then Normal in Temp
Temp 30-40 then Its Hot
Temp >=40 then Its Very Hot

Sample Solution:-

C# Sharp Code:

using System;  
public class Exercise13  
{  
    public static void Main()
{
     int tmp;
    Console.Write("\n\n");
    Console.Write("Accept a temperature in centigrade and display a suitable message:\n");
    Console.Write("--------------------------------------------------------------------");
    Console.Write("\n\n");

    Console.Write("Input days temperature : ");
    tmp= Convert.ToInt32(Console.ReadLine());
   if(tmp<0)
             Console.Write("Freezing weather.\n");
   else if(tmp<10)
            Console.Write("Very cold weather.\n");
            else if(tmp<20)
                        Console.Write("Cold weather.\n");
                    else if(tmp<30)
                               Console.Write("Normal in temp.\n");
                            else if(tmp<40)
                                         Console.Write("Its Hot.\n");
                                    else
                                           Console.Write("Its very hot.\n");

}
}

Sample Output:

Accept a temperature in centigrade and display a suitable message:                                            
--------------------------------------------------------------------
Input days temperature : 35                                                                                   
Its Hot. 

Pictorial Presentation:

Conditional Statement: Accept a temperature in centigrade and display a suitable message.

Flowchart:

Flowchart: Accept a temperature in centigrade and display a suitable message.

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a C# Sharp program to read roll no, name and marks of three subjects and calculate the total, percentage and division.
Next: Write a C# Sharp program to check whether a triangle is Equilateral, Isosceles or Scalene.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.