# why doesn't this work?

#include <stdio.h>

int main ()

{

printf ("Give me three integers:\n");

int x1, x2, x3, a;char g;

scanf ("%d%d%d", &x1, &x2, &x3);

printf ("\nSelect one of the following letters to perform a logical operation:\n"); printf ("A\tLogical AND\nO\tLogical OR\n");

scanf ("%s", &g);

switch (g)

{ case 'A': { if (x1 && x2 && x3)

a = 1;

else

a = 0; printf ("%d\tAND\t%d\tAND\t%d\t=\t%d\n", x1, x2, x3, a);

break; }

case 'O':

{ if (x1 || x2 || x3)

a = 1;

else a = 0;

printf ("%d\tOR\t%d\tOR\t%d\t=\t%d\n", x1, x2, x3, a);

break; } }

return 0;

}

answered Apr 2, 2019 by (140 points)

use

scanf ("%c", &g);

answered Apr 23, 2019 by (260 points)

try this

#include <stdio.h>

int main ()

{

printf ("Give me three integers:\n");

int x1, x2, x3, a;char g;

scanf ("%d%d%d", &x1, &x2, &x3);

printf ("\nSelect one of the following letters to perform a logical operation:\n"); printf ("A\tLogical AND\nO\tLogical OR\n");

scanf ("%s", &g);

switch (g)

{ case 'A': { if (x1 && x2 && x3)

a = 1;

else

a = 0; printf ("%d\tAND\t%d\tAND\t%d\t=\t%d\n", x1, x2, x3, a);

break; }

case 'O':

{ if (x1 || x2 || x3)

a = 1;

else a = 0;

printf ("%d\tOR\t%d\tOR\t%d\t=\t%d\n", x1, x2, x3, a);

break; } }

return 0;
}