/* This program calculates the Ohms's Law OHMS.CPP Name : Yidong, Shin Student Number : 011-655-057 Program : PRG155 */ #include #include #include main () { float V, I, R; int choice; // this variable used for choice char reply; /*** Input Stage ***/ clrscr(); printf ("This program calculates V or I or R using Ohm's Law.\n"); printf ("\nChoose a number to calculate:"); printf ("\n1. Voltage"); printf ("\n2. Current"); printf ("\n3. Resistance"); printf ("\n0. Exit"); printf ("\n > "); scanf("%d", &choice); /*** Processing Stage for 1 ***/ if (choice==1) { printf ("\nEnter current > "); scanf("%f", &I); printf ("\nEnter resistance > "); scanf("%f", &R); V = I * R; /*** Output Stage for 1 ***/ printf ("\nThe volatge is %.2f volts\n", V); printf ("\ndo you want to quit (y/n) > "); fflush(stdin); scanf ("%c", &reply); if (reply == 'y' || reply == 'Y') exit(0); } /*** Processing Stage for 2 ***/ else if (choice==2) { printf ("\nEnter voltage > "); scanf("%f", &V); printf ("\nEnter resistance > "); scanf("%f", &R); I = V / R; /*** Output Stage for 2 ***/ printf ("\nThe current is %.2f amps\n", I); printf ("\ndo you want to quit (y/n) > "); fflush(stdin); scanf ("%c", &reply); if (reply == 'y' || reply == 'y') exit(0); } /*** Processing Stage for 3 ***/ else if (choice==3) { printf ("\nEnter voltage > "); scanf("%f", &V); printf ("\nEnter current > "); scanf("%f", &I); R = V / I; /*** Output Stage for 3 ***/ printf ("\nThe resistance is %.2f ohms\n", R); printf ("\ndo you want to quit (y/n) > "); fflush(stdin); scanf ("%c", &reply); if (reply == 'y' || reply == 'y') exit(0); } /*** Processing Stage for 0 ***/ else if (choice==0) { /*** Output Stage for 0 ***/ printf ("\nQuitting... Hit Any Key to Exit"); fflush(stdin); getch(); exit(0); } }