-
Program skips scanf
I have the following code, and it works fine, except for when it gets to the last if statement. The scanf inside the if statement is skipped and the program ends. Can anyone tell me why this happens? I've tried putting printf statements inside the last if, and they work fine.
Code:
#include <stdio.h>
#include <ctype.h>
#define J 30
int main (void)
{
int i, order;
char first_name[J], initial[J], last_name[J];
printf ("Please enter your first, middle and then last name.\n");
scanf ("%s %s %s", first_name, initial, last_name);
i=0;
first_name[i] = toupper(first_name[i]);
initial[i] = toupper (initial[i]);
while (i<J)
{
last_name [i] = toupper (last_name[i]);
i++;
}
printf ("\n");
printf ("MORTGAGE CALCULATIONS PRINTED SPECIALLY FOR %s %.1s. %s\n\n", first_name, initial, last_name);
printf ("We offer the following terms for mortgages (in years).\n");
printf ("Please select a term by choosing its order number:\n\n");
printf ("1. 5 years\n");
printf ("2. 6 years\n");
printf ("3. 7 years\n");
printf ("4. 10 years\n");
printf ("5. 18 years\n");
while (scanf ("%d", &order)!=1)
{
printf ("Please enter an order number from 1-5\n");
fflush (stdin);
}
if (getchar ()!='\n')
{
scanf ("%d", &order);
}
return 0;
}
-
Nevermind, have found my dumb mistake.
-