Write an if statement involving a boolean operator (and, or or not) which performs the same function as the following nested if statement: if day == "sunny" if temperature > 20 picnic = "yes" else picnic = "no" endif endif

Respuesta :

The given question requires that we need to rewrite the if-else statement using boolean operators such as “and”, “or”, and “or not

The if-else statement is used to evaluate the condition and execute some instruction or perform some task in case the condition is true, otherwise, execute the else part of the if-else statement.

In the if-else conditions, you can evaluate the expression using boolean operators such as and, or, on not, etc.

The given statement can be rewritten in any programming language. But here we use C++ to rewrite the given statement involving boolean operators:

Use of “and” operator:

#include <iostream>

using namespace std;

int main()

{

   string day = "sunny";

   int temperature =10;

   string picnic = "Yes";

 

   if (day =="sunny" && temperature ==10)

   {

       picnic = "Yes";

       std::cout<<picnic;}

   else

   {

       picnic="No";

       std::cout<<picnic;}

   return 0;

}

Use of “or” operator:

#include <iostream>

using namespace std;

int main()

{

   string day = "sunny";

   int temperature =10;

   string picnic = "Yes";

 

   if (day =="sunny" || temperature ==10)

   {

       picnic = "Yes";

       std::cout<<picnic;}

   else

   {

       picnic="No";

       std::cout<<picnic;}

   return 0;

}

Use of “or not” operator:

#include <iostream>

using namespace std;

int main()

{

   string day = "sunny";

   int temperature =10;

   string picnic = "Yes";

 

   if (!(day =="sunny"|| temperature ==10))

   {

       picnic = "Yes";

       std::cout<<picnic;}

   else

   {

       picnic="No";

       std::cout<<picnic;}

   return 0;

}

You can learn more about if-else statement at

https://brainly.com/question/18736215

#SPJ4

ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE