OK, fixed the scanf problem. I implemented the for loop in this manner:
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int choice;
char band1, band2, band3, band4;
for (choice=0;choice!=3;choice)
{
printf ("\nThis program calculates the resistor value based on the colours of the wire.\n(enter the integer near the command)\n");
printf ("What would you like to do?\n1. Calculate resistance value.\n2. Help.\n3. Exit.\n");
scanf ("%d", &choice);
switch (choice)
{
case 1:
printf ("B=Black\nN=Brown\nO=Orange\nY=Yellow\nG=Green\n");
printf ("L=Blue\nV=Violet\n\A=Gray\nW=White\nD=Gold\nS=Silver\n");
printf ("What is the colour of the first, second, third, and fourth bands?\n");
scanf (" %c\n", &band1);
scanf (" %c\n", &band2);
scanf (" %c\n", &band3);
scanf (" %c", &band4);
printf ("%c %c %c %c", band1,band2,band3,band4);
break;
case 2:
printf ("This program takes the four colours of the bands of a resistor and uses them to\ncalculate the resistance of the resistor. ");
printf ("When first entering the program, you\nare displayed with three functions: calculate the value of the resistance,\n");
printf ("help, and exit. Help leads here, while exit exits the program. Calculating the\nfunction leads to the main part ");
printf ("of the program. In there, you will be given a\ntable of different colours and the letter corresponding to each colour. ");
printf ("You are instructed to enter the colours of the first, second, third (M), and fourth (T) bands. MAKE SURE to enter the ");
printf ("capital of the letter that corresponds to each\ncolour if you want the program to work. The program will calculate ");
printf ("the\nresistance with the allowed tolerance. Happy using the program!\n");
break;
case 3:
exit(main);
default:
printf ("ERROR! THIS VALUE DOES NOT CORRESPOND TO A FUNCTION! BOMBING THE HOUSE NOW!\n");
break;
}
}
system("pause");
return 0;
}
However, the code breaks when at the starting menu, you enter a letter instead of a number (it keeps looping). How do I fix this?