w3resource

C++ Exercises: Check if one given temperatures is less than 0 and the other is greater than 100

C++ Basic Algorithm: Exercise-13 with Solution

Write a C++ program to check if one given temperature is less than 0 and the other is greater than 100.

Sample Solution:

C++ Code :

#include <iostream>
using namespace std;

bool test(int temp1, int temp2)
        {
            return temp1 < 0 && temp2 > 100 || temp2 < 0 && temp1 > 100;
        }
        
int main() 
 {
  cout << test(120, -1) << endl;  
  cout << test(-1, 120) << endl;  
  cout << test(2, 120) << endl;  
  return 0;    
}

Sample Output:

1
1
0

Pictorial Presentation:

C++ Basic Algorithm Exercises: Check if one given temperatures is less than 0 and the other is greater than 100.

Flowchart:

Flowchart: Check if one given temperatures is less than 0 and the other is greater than 100.

C++ Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a C++ program to check if a given string starts with 'C#' or not.
Next: Write a C++ program to check two given integers whether either of them is in the range 100..200 inclusive.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.

C++ Programming: Tips of the Day

What is the "-->" operator in C/C++?

--> is not an operator. It is in fact two separate operators, -- and >.

The conditional's code decrements x, while returning x's original (not decremented) value, and then compares the original value with 0 using the > operator.

To better understand, the statement could be written as follows:

while( (x--) > 0 )

Ref : https://bit.ly/3kOTBby





We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook