You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1007 B

11 months ago
11 months ago
11 months ago
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "operationHandler.h"
  4. char buffer[100];
  5. int main() {
  6. printf("Please enter the id of a specific operation...\n1. addition\n2. subtraction\n3. multiplication\n4. division\n");
  7. // input for math operation as integer
  8. int input;
  9. scanf("%d", &input);
  10. // check if operation input is valid
  11. if(!checkOperationInput(input)) {
  12. printf("Invalid operation id\n");
  13. return 0;
  14. }
  15. printf("\nPlease enter the first and the second number separated by a space...\n");
  16. // loop to enter numbers for calculation
  17. while(fgets(buffer, 100, stdin)) {
  18. buffer[strcspn(buffer, "\n")] = '\0';
  19. if (strlen(buffer) > 0) {
  20. break;
  21. }
  22. }
  23. // extracting numbers from input
  24. int* result = evaluateInput(buffer, input);
  25. if(result == NULL) {
  26. printf("\nInvalid formatting. Two numbers need to be separated by a space\n");
  27. return 0;
  28. }
  29. printf("\nResult: %d", *result);
  30. }