Browse Source

refactoring: made an extra function(getIntegerInput) which helps read and print user value in a single step

remotes/origin/kabrel
fdai7782 11 months ago
parent
commit
941e7584b7
  1. 14
      src/main/c/programmingMode.c

14
src/main/c/programmingMode.c

@ -5,6 +5,14 @@
#include "taschenrechner.h" #include "taschenrechner.h"
// get the NUmbers from the user
int getIntegerInput(const char* prompt) {
int num;
printf("%s", prompt);
scanf("%d", &num);
return num;
}
// Calculation // Calculation
int performOperation(int num1, char operator, int num2) { int performOperation(int num1, char operator, int num2) {
switch (operator) { switch (operator) {
@ -31,14 +39,12 @@ void programmingMode() {
int num1, num2, result; int num1, num2, result;
char operator; char operator;
printf("Enter first integer: ");
scanf("%d", &num1);
num1 = getIntegerInput("Enter first integer: ");
printf("Enter operator (+, -, *, /): "); printf("Enter operator (+, -, *, /): ");
scanf(" %c", &operator); scanf(" %c", &operator);
printf("Enter second integer: ");
scanf("%d", &num2);
num2 = getIntegerInput("Enter second integer: ");
// Calculation + Display the result // Calculation + Display the result

Loading…
Cancel
Save