Why getChar doesn't work when I get an operator input when I make a calculator.
Code:
#include <cstdio>
//Enter a mistake
float getFloat();
//Enter Operator
char getChar();
int main() {
float value1;
float value2;
char oper;
float result = 0;
value1 = getFloat();
value2 = getFloat();
oper = getchar();
switch (oper) {
(Broadcast)
default:
printf ("invalid operator).");
break;
}
}
float getFloat() {
float input;
printf ("Please enter a mistake: ");
scanf_s("%f", &input);
return input;
}
char getChar() {
char input;
printf (please enter operator : ");
scanf_s("%c", &input);
return input;
}
When you build, you can receive up to two mistakes, but as soon as you receive the second one, the word incorrect operator is printed and it ends.