#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNING
#endif
#include <stdio.h> // basic I/O printf
#include <stdlib.h> // malloc, calloc, realloc
#include <string.h> // strcpy
#include <time.h>
/*Arithmatic practice*/
int main() {
/*Variable declaration*/
char o;
char c;
int a, b;
while (1) {
printf("Enter values a, operator and b\n");
scanf("%d %c %d", &a, &o, &b);
if (o == '+') {
printf("%d %c %d = %d \n", a, o, b, a + b);
}
else if (o == '*') {
printf("%d %c %d = %d \n", a, o, b, a * b);
}
else if (o == '/') {
printf("%d %c %d = %f \n", a, o, b, a / b);
}
else if (o == '-') {
printf("%d %c %d = %d \n", a, o, b, a - b);
}
else{
printf("Invalid Input \n");
}
printf("Do you want to exit Y/N \n");
scanf("%c", &o); // this part does not execute
if (o == 'N' || o == 'n') {
continue;
}
else if (o == 'Y' || o == 'y') {
break;
}
else{
printf("Invalid Input \n");
}
}
printf("successfully exited");
return 0;
}
when I run this code, the below scanf function is ignored and is not executed. Could someone help me out to figure out this? I honestly have no idea why this code is not working.
scanf("%c", &o) //ignored and not executed;
My assumption is overwriting o has something to do with this but not really sure why this code is not working because this is supposed to be an example code and I saw this code was working on a video.
Is it possible that exactly the same code is not working on a different IDE?