C#: Check whether one of the given temperatures is less than 0 and the other is greater than 100
Temperature Comparison
Write a C# Sharp program that checks whether one temperature is less than 0 and another is greater than 100.
Visual Presentation:

Sample Solution:
C# Sharp Code:
using System;
// Namespace declaration
namespace exercises
{
// Class declaration
class Program
{
// Main method - entry point of the program
static void Main(string[] args)
{
// Calling the 'test' method with different integers and displaying the returned values
Console.WriteLine(test(120, -1)); // Output: True
Console.WriteLine(test(-1, 120)); // Output: True
Console.WriteLine(test(2, 120)); // Output: False
Console.ReadLine(); // Keeping the console window open
}
// Method to test conditions based on two integer values
public static bool test(int temp1, int temp2)
{
// Check if temp1 is less than 0 AND temp2 is greater than 100
// OR check if temp2 is less than 0 AND temp1 is greater than 100
// Return true if either of these conditions is met; otherwise, return false
return temp1 < 0 && temp2 > 100 || temp2 < 0 && temp1 > 100;
}
}
}
Sample Output:
True True False
Flowchart:

For more Practice: Solve these Related Problems:
- Write a C# program to check if one temperature is above 100 and the other is below -100.
- Write a C# program to determine if both temperatures are either above 0 or below 0.
- Write a C# program to validate if one temperature is in the boiling range and another in the freezing range.
- Write a C# program that returns true if the average of two temperatures is exactly 60 or more than 100.
Go to:
PREV : Starts with 'C#'.
NEXT : One Integer in Range 100-200.
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.