This C++ program implements DeMorgan's laws by presenting the user with 4 examples of logical equivalencies and checking if statements are true or false. It prompts the user to input values for variables and checks if !(p && q) = !p || !q and !(p || q) = !p && !q. The program uses a do-while loop to allow the user to try multiple examples for each equivalence and exits the loop when the user enters 'n'.
This C++ program implements DeMorgan's laws by presenting the user with 4 examples of logical equivalencies and checking if statements are true or false. It prompts the user to input values for variables and checks if !(p && q) = !p || !q and !(p || q) = !p && !q. The program uses a do-while loop to allow the user to try multiple examples for each equivalence and exits the loop when the user enters 'n'.
This C++ program implements DeMorgan's laws by presenting the user with 4 examples of logical equivalencies and checking if statements are true or false. It prompts the user to input values for variables and checks if !(p && q) = !p || !q and !(p || q) = !p && !q. The program uses a do-while loop to allow the user to try multiple examples for each equivalence and exits the loop when the user enters 'n'.
printf("%s", "Want more examples of this logical equivalency? "); getchar(); scanf("%c", &ch); } while (ch == 'y'); // choose yes to continue with current part, or no to move on
if (ch == 'n') {
do { puts("\nShow that (!(a == b) || !(g != 5)) and !((a == b) && (g != 5)) are logically equivalent\n\n");
// input a, b, and g values printf("%s", "Enter a: "); scanf("%2u", &a); printf("%s", "Enter b: "); scanf("%2u", &b); printf("%s", "Enter g: "); scanf("%2u", &g);
// if statement to handle logical equivalency if ((!(a == b) || !(g != 5)) && !((a == b) && (g != 5))) { printf("%s", "True!\n\n"); } else { printf("%s", "False!\n\n"); } printf("%s", "Want more examples of this logical equivalency? "); getchar(); scanf("%c", &ch); } while(ch == 'y'); // choose yes to continue with current part, or no to move on }
if (ch == 'n') {
do { puts("\nShow that !((x <= 8) && (y > 4)) and (!(x <= 8) || !(y > 4)) are logically equivalent\n\n");
// input x and y values printf("%s", "Enter x: "); scanf("%2u", &x); printf("%s", "Enter y: "); scanf("%2u", &y);
// if statement to handle logical equivalency if (!((x <= 8) && (y > 4)) && (!(x <= 8) || !(y > 4))) { printf("%s", "True!\n\n"); } else { printf("%s", "False!\n\n"); } printf("%s", "Want more examples of this logical equivalency? "); getchar(); scanf("%c", &ch); } while (ch == 'y'); // choose yes to continue with current part, or no to move on }
if (ch == 'n') {
do { puts("\nShow that !((i > 4) || (j <= 6)) and (!(i > 4) && !(j <= 6)) are logically equivalent\n\n");
// input i and j values printf("%s", "Enter i: "); scanf("%2u", &i); printf("%s", "Enter j: "); scanf("%2u", &j);
// if statement to handle logical equivalency if (!((i > 4) || (j <= 6)) && (!(x <= 8) && !(y > 4))) { printf("%s", "True!\n\n"); } else { printf("%s", "False!\n\n"); } printf("%s", "Want more examples of this logical equivalency? "); getchar(); scanf("%c", &ch); } while (ch == 'y'); // choose yes to continue with current part, or no to move on }
if (ch == 'n') { printf("\n%s", "Now you know DeMorgan's Laws!"); }