Alright, I've tried to make my program simpler, but still getting some infinite loops instead of error messages.
Code:
#include <stdio.h>
#include <math.h>
void main()
{
char error_bell = 7;
int user_choice, choice4, band_1, band_2;
int band_3, band_4;
float resistance;
while (user_choice!=3) /*This while loop is there so that the user will be returned to the main prompt after reading the help */
{
printf("Please choose an option:\n");
printf("\t 1. Calculate resistance\n");
printf("\t 2. Help\n");
printf("\t 3. EXIT\n");
//while (user_choice!=1 || user_choice!=2 || user_choice!=3)
//{
printf("\nEnter selection:");
scanf("%d", &user_choice);
//}
if (user_choice==1)
{
printf("\nPlease enter the colour of the first band\n");
printf("0 for Black\t 1 for Red\t 2 for Brown\n");
printf("3 for Orange\t 4 for Yellow\t 5 for Green\n");
printf("6 for Blue\t 7 for Violet\t 8 for Gray\n");
printf("9 for White.\n");
scanf("%d", &band_1);
printf("\nPlease enter the colour of the second band\n");
printf("0 for Black\t 1 for Red\t 2 for Brown\n");
printf("3 for Orange\t 4 for Yellow\t 5 for Green\n");
printf("6 for Blue\t 7 for Violet\t 8 for Gray\n");
printf("9 for White.\n");
scanf("%d", &band_2);
printf("\nPlease enter the colour of the third band\n");
printf("0 for Black\t 1 for Red\t 2 for Brown\n");
printf("3 for Orange\t 4 for Yellow\t 5 for Green\n");
printf("6 for Blue\t 7 for Violet\t 8 for Gray\n");
printf("9 for White\t -1 for Gold\t -2 for silver.\n");
scanf("%d", &band_3);
printf("\nPlease enter the colour of the fourth band\n");
printf("1 for Gold\t 2 for Silver");
scanf("%d", &choice4);
if (choice4==1)
band_4 = 5;
if (choice4==2)
band_4 = 10;
resistance=((band_1*10)+band_2)*pow(10, band_3);
if (resistance < 1000.0)
printf("\nThis is the resistance %f ohms +- %d percent error\n\n", resistance, band_4);
if (resistance >=1000.0 && resistance<1000000.0)
{
resistance=resistance/1000.0;
printf("\nThe resistance is %f kilo Ohms +- %d percent error\n\n", resistance, band_4);
}
if (resistance>=1000000.0 && resistance<1000000000.0)
{
resistance=resistance/1000000.0;
printf("\nThe resistance is %f Mega Ohms +- %d percent error\n\n", resistance, band_4);
}
}
if (user_choice==2)
printf("\nTo use this program, simply input the number corresponding to the colour on the resistor\n.");
if (user_choice==3)
{
printf("\nGood day!");
}
//else
//printf("Invalid input\n");
}
}