Browse Source

refactoring: made an extra function(getOperatorInput) which helps read and print user's operation value in a single step

remotes/origin/kabrel
fdai7782 12 months ago
parent
commit
a1cd5bd996
  1. 13
      src/main/c/programmingMode.c

13
src/main/c/programmingMode.c

@ -13,6 +13,14 @@ int getIntegerInput(const char* prompt) {
return num;
}
// Display the diffrent operations and scan them
char getOperatorInput() {
char operator;
printf("Enter operator (+, -, *, /): ");
scanf(" %c", &operator);
return operator;
}
// Calculation
int performOperation(int num1, char operator, int num2) {
switch (operator) {
@ -40,10 +48,7 @@ void programmingMode() {
char operator;
num1 = getIntegerInput("Enter first integer: ");
printf("Enter operator (+, -, *, /): ");
scanf(" %c", &operator);
operator = getOperatorInput();
num2 = getIntegerInput("Enter second integer: ");
// Calculation + Display the result

Loading…
Cancel
Save