C Code
C Code
printf("Menu Options:\n");
printf("1. Resistance Calculations\n");
printf("2. Voltage Calculations\n");
printf("3. Current Calculations\n");
printf("4. Exit Program\n");
}
int main() {
int choice = 0;
float voltage = 0.0, current = 0.0;
int resistance = 0;
while (choice != 4) {
displayMenu();
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1: // Resistance Calculation
printf("Please enter the applied voltage (V): ");
scanf("%f", &voltage);
printf("Please enter the current (mA): ");
scanf("%f", ¤t);
if (current == 0) {
printf("You cannot enter a current of zero.\n");
} else if (current < 0 || voltage < 0) {
printf("Negative numbers are not allowed!\n");
} else {
float resistance = voltage / (current / 1000);
printf("The resistance is %.4f ohms.\n", resistance);
}
break;
if (resistance == 0) {
printf("You cannot enter a resistance of zero.\n");
} else if (resistance < 0 || voltage < 0) {
printf("Negative numbers are not allowed!\n");
} else {
float current = (voltage / resistance) * 1000;
printf("The current is %.1f milli amps.\n", current);
}
break;
case 4: // Exit
printf("Quitting...\n");
break;
return 0;
}