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.
38 lines
1007 B
38 lines
1007 B
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "operationHandler.h"
|
|
|
|
char buffer[100];
|
|
|
|
int main() {
|
|
printf("Please enter the id of a specific operation...\n1. addition\n2. subtraction\n3. multiplication\n4. division\n");
|
|
|
|
// input for math operation as integer
|
|
int input;
|
|
scanf("%d", &input);
|
|
|
|
// check if operation input is valid
|
|
if(!checkOperationInput(input)) {
|
|
printf("Invalid operation id\n");
|
|
return 0;
|
|
}
|
|
|
|
printf("\nPlease enter the first and the second number separated by a space...\n");
|
|
|
|
// loop to enter numbers for calculation
|
|
while(fgets(buffer, 100, stdin)) {
|
|
buffer[strcspn(buffer, "\n")] = '\0';
|
|
if (strlen(buffer) > 0) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
// extracting numbers from input
|
|
int* result = evaluateInput(buffer, input);
|
|
|
|
if(result == NULL) {
|
|
printf("\nInvalid formatting. Two numbers need to be separated by a space\n");
|
|
return 0;
|
|
}
|
|
printf("\nResult: %d", *result);
|
|
}
|