What everyone else here is saying is true, getchar()
returns an int
but that's not your problem.
The problem is that getchar()
leaves a newline character after you use it. If you're going to use getchar()
you must always consume the newline char afterwards. This simple fix:
printf("\t What sort of operation would you like to perform? \n \t Type + - * / accordingly. \n");
c = getchar();
getchar(); //<-- here we do an extra getchar for the \n
printf("\tplease enter a number \n");
scanf("%d",&number[0]);
printf("\tplease enter another number \n");
scanf("%d",&number[1]);
and that will eliminate the problem. Every time you type <somechar><enter>
it's really putting two characters on the buffer, for example if I hit + and enter I'm getting:
'+''\n' // [+][\n]
getchar()
will only get the first of these, then when getchar()
is called again it won't wait for your input it will just take that '\n'
and move on to the scanf()