C++ Logical Operators Question

Introduction

Write a program that defines a variable of type int.

Assign the value of 256 to the variable.

Check if the value of this variable is greater than 100 and less than 300.

Then, define a boolean variable with a value of true.

Check if the int number is greater than 100, or the value of a bool variable is true.

Then define a second bool variable whose value will be the negation of the first bool variable.

You can use the following code structure.

#include <iostream> 

int main() 
{ 
    //your code here
} 


#include <iostream> 

int main() 
{ 
    int x = 256; 
    if (x > 100 && x < 300) 
    { 
         std::cout << "The value is greater than 100 and less than 300."   
          << '\n'; 
    } 
    else 
    { 
         std::cout << "The value is not inside the (100 .. 300) range."   
          << '\n'; 
    } 

    bool mycondition = true; 
    if (x > 100 || mycondition) 
    { 
         std::cout << "Either x is greater than 100 or the bool variable is  
          true." << '\n'; 
    } 
    else 
    { 
         std::cout << "x is not greater than 100 and the bool variable is  
          false." << '\n'; 
    } 

    bool mysecondcondition = !mycondition; 
} 



PreviousNext

Related