/* * simulator.c * * * Created by xwu3 on 3/1/09. * Copyright 2009 University of Iowa. All rights reserved. * */ #include void IllumateRedBulb(int A, int B); void IllumateBlueBulb(int A, int B, int C); void IllumateGreenBulb(int A); int main (void) { int switch1 = 0, switch2 = 0, switch3 = 0, switch4 = 0, switch5 = 0, switch6 = 0; int input; 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 */ IllumateRedBulb(switch1, switch2); IllumateBlueBulb(switch3, switch4, switch5); IllumateGreenBulb(switch6); } } while (input != -1); return 0; } void IllumateRedBulb(int A, int B) /* Illumate Red Bulb */ { if (A && B) printf("Red\n"); } void IllumateBlueBulb(int A, int B, int C) /* Illumate Blue Bulb */ { int xorA; int blueBulb; xorA = A || B; blueBulb = (!xorA && C) || (xorA && !C); if (blueBulb) printf("Blue\n"); } void IllumateGreenBulb(int A) /* Illumate Green Bulb */ { if (A) printf("Green\n"); }