What am I doing wrong here? I've tried this in the main, I've tried it in a function using a return statement, and here is my attempt to pass a pointer to a character (a math operator--this is supposed to be a calculator program) into a loop. It goes in the first time, but then after that it ignores the input of the character and just prints out the statements without waiting for input. Can you look at this program fragment and tell me what to do to fix it?
Thanks a lot.
Donna
#include <stdio.h>
void get_operator(char *lop);
int get_operand();
void main(){
// int num1=0;
char op;
int num2=0;
// int accum=0;
int i;
for (i =1; i < 4; ++i){
get_operator(&op);
printf("the operator is %c\n", op);
num2 = get_operand();
printf("operand is %d\n", num2);
}
printf("the final result is %d\n", num2);
}
void get_operator( char *lop){
printf("enter a math operator or q to quit> ");
scanf("%c", lop);
}
int get_operand(){
int lnum2; /* local variable for operand */
printf("enter an integer >");
scanf("%d", &lnum2);
return lnum2;
}
}