Possible Duplicate:
C: function skips user input in code
#include <stdio.h>
int main (int argc, const char * argv[])
{
char item;
int row;
int size;
int price_list[5][8] =
{
{9,18,27,36,45,54,63,72},
{10,20,30,40,50,60,70,80},
{11,22,33,44,55,66,77,88},
{12,24,36,48,60,72,84,96},
{13,26,39,52,65,78,91,104}
};
do {
printf("Please enter the item:\n");
scanf("%c", &item);
printf("Please enter the size:\n");
scanf("%d", &size);
switch (item) {
case 'e':
row = 0;
break;
case 't':
row = 1;
break;
case 's':
row = 2;
break;
case 'u':
row = 3;
break;
case 'd':
row = 4;
break;
default:
row = 5;
break;
}
if (row < 5) {
printf("%d\n", price_list[row][size]);
}
}
while (item != 'q');
return 0;
}
the loop runs properly for the first time and then it prints the two printf statements at once like Please enter the item: e Please enter the size: 1 18 Please enter the item: Please enter the size:
Why does this happen?