Testing if Both Boolean Expressions Are True : If « Language « C++






Testing if Both Boolean Expressions Are True

Testing if Both Boolean Expressions Are True

#include <iostream>
using namespace std;
int main(void)
{
   int age;
   char choice;
   bool citizen;
   cout << "Enter your age: ";
   cin >> age;
   cout << "Are you a citizen (Y/N): ";
   cin >> choice;
   if (choice == 'Y')
      citizen = true;
   else
      citizen = false;
   if (age >= 18)
      if(citizen == true)
         cout << "You are eligible to vote";
      else
         cout << "You are not eligible to vote";
   else
      cout << "You are not eligible to vote";
   return 0;
}


           
       








Related examples in the same category

1.Testing if Either Boolean Expression Is TrueTesting if Either Boolean Expression Is True
2.Add an else part to the if statementAdd an else part to the if statement
3.The use of if-else statementsThe use of if-else statements
4.Conditional ExpressionsConditional Expressions
5.if /else if /else statement in actionif /else if /else statement in action
6.Use an int value to control the if. Use an int value to control the if.
7.Nested if statementNested if statement