I am totally new to C programming, and now, as I am writing my first program, I have encountered a problem with breaking from a while loop. Here is my code:
#include <stdio.h>
#include <stdlib.h>
int multipl(int x, int y);
int main(){
int x, y, result;
char replyChar;
while (1){
printf("Enter two numbers to be multiplied: \n");
printf("Number A: "); scanf("%d", &x);
printf("\nNumber B: "); scanf("%d", &y);
result = multipl(x, y);
printf("\nThe product of %d and %d is %d", x, y, result);
printf("\nDo you wish to proceed?(y/n): ");
scanf("%c", &replyChar);
if (replyChar == 'n'){
printf("Exiting the program.. :)");
break;
}
else{
continue;
}
}
return 0;
}
int multipl(int x, int y){
return x * y;
}
The problem is that after function 'multipl' returns a result and the 'Do you wish to proceed' phrase comes on, the code does not wait for receiving the replyChar, and just prints printf("Enter two numbers to be multiplied: \n");
.
How can I make my code wait for the replyChar without going on further? Thanks in advance for your help!