Ok, here are the two functions I using:
int Get_Valid_Type()
{
int type;
gotoxy(3,4);
textcolor(YELLOW);
cprintf("Types of Seeds:\n");
gotoxy(5,5);
textcolor(RED);
cprintf("1.");
textcolor(WHITE);
cprintf(" Wheat ");
textcolor(RED);
cprintf("2.");
textcolor(WHITE);
cprintf(" Rice ");
textcolor(RED);
cprintf("3.");
textcolor(WHITE);
cprintf(" Rye ");
textcolor(RED);
cprintf("4.");
textcolor(WHITE);
cprintf(" Oats ");
textcolor(RED);
cprintf("5.");
textcolor(WHITE);
cprintf(" Barley ");
textcolor(RED);
cprintf("6.");
textcolor(WHITE);
cprintf(" Corn ");
textcolor(RED);
cprintf("7.");
textcolor(WHITE);
cprintf(" Sorghum ");
textcolor(RED);
cprintf("8.");
textcolor(WHITE);
cprintf("Other");
gotoxy(3,7);
textcolor(GREEN);
cprintf("Select type of seed:");
textcolor(BLUE);
gotoxy(24,7);
fflush(stdin);
cscanf("%d",&type);
if (type == 0 || type > 8)
{
gotoxy(23,9);
textcolor(RED);
cprintf("ERROR! Please enter from menu");
Get_Valid_Type();
}
else if (type >= 1 && type <=8)
{
return type;
}
fflush(stdin);
}
char Get_Valid_Age()
{
char age;
gotoxy(3,4);
textcolor(YELLOW);
cprintf("Age of Seeds:");
gotoxy(5,5);
textcolor(RED);
cprintf("C:");
textcolor(WHITE);
cprintf(" Cold Storage ");
textcolor(RED);
cprintf("L:");
textcolor(WHITE);
cprintf(" Last Years Stock ");
textcolor(RED);
cprintf("F:");
textcolor(WHITE);
cprintf(" Fresh ");
gotoxy(3,7);
textcolor(GREEN);
cprintf("Select C, L, or F: ");
gotoxy(22,7);
textcolor(BLUE);
do {
cscanf("%[CLF]",&age);
fflush(stdin);
if (age == 0)
{
gotoxy(23,9);
textcolor(RED);
cprintf("ERROR! Invalid selection. Try again");
}
} while(age == 0);
return age;
}
the first function has to return a value from 1 to 8. and nothing else. the second function has to return one of the three letters. problem is whenever I run this program after I type in the input for the first function it goes through 2nd function and makes the Error message appear and doesn't let me type in the 2nd input. I think is something to do with the memory locations of where the variables are being stored.
This is a program for school if you were wondering and this is the only bug that appears now. Thanks in advance to the people that help. If you want more code, just post.