/* * simulator.c * * * Created by xwu3 on 3/1/09. * Copyright 2009 University of Iowa. All rights reserved. * */ #include int main (void) { int switch1 = 0, switch2 = 0, switch3 = 0, switch4 = 0, switch5 = 0, switch6 = 0; int redBulb = 0, blueBulb = 0, greenBulb = 0; int input; int xorA; do { printf("\n\n\nEnter a switch to close.\n"); /* Print menu */ printf("\t1: Switch One\n"); printf("\t2: Switch Two\n"); printf("\t3: Switch Three\n"); printf("\t4: Switch Four\n"); printf("\t5: Switch Five\n"); printf("\t6: Switch Six\n"); printf("\t-1: Exit\n"); scanf("%d", &input); switch (input) { /* close the switch */ case 1: switch1 = 1; break; case 2: switch2 = 1; break; case 3: switch3 = 1; break; case 4: switch4 = 1; break; case 5: switch5 = 1; break; case 6: switch6 = 1; break; case -1: break; default: printf("Invalid switch.\n"); break; } if (input != -1) { /* simulate the logical circuit */ redBulb = switch1 && switch2; if (redBulb) printf("Red\n"); xorA = switch3 || switch4; blueBulb = (!xorA && switch5) || (xorA && !switch5); if (blueBulb) printf("Blue\n"); greenBulb = switch6; if (greenBulb) printf("Green\n"); } } while (input != -1); return 0; }