#include <stdio.h>
#include <stdlib.h>
#include "mathMaster.h"
int main() {
FILE *score;
double x;
double y;
double z;
int c;
int scores;
scores = 0;
while (1) {
"Enter 's' to input two double values, and the sum of these values: \n");
"Enter 'p' to input two double values, and the product of these values: \n");
"Enter 'd' to input two double values, and the difference of these values: \n");
"Enter 'm' to input two double values, and the maximum of these values: \n");
"Enter 'n' to input two double values, and the minimum of these values: \n");
printf("Enter 'q' to quit.\n");
c = getchar();
while (getchar() != '\n') {
;
}
if ((c == 'q') || (c == 'Q')) { /* Checking if user chose to quit program */
if ((score = fopen("a4.score", "r")) != NULL) {
fprintf(stderr,
"Score file exists, would you like to overwrite? (Y/N)\n ");
c = getchar();
}
while (getchar() != '\n') {
;
}
if (fclose(score) == EOF) {
fprintf(stderr, "File cannot close properly\n");
return EXIT_FAILURE;
}
if (!(c == 'y' || c == 'Y')) {
fprintf(stderr,
"Leaving score file untouched, terminating program.\n");
return EXIT_SUCCESS;
}
if ((score = fopen("a4.score", "w")) == NULL) {
fprintf(stderr, "Cannot open scores. \n");
return EXIT_FAILURE;
}
fprintf(score, "Your score is: %d", scores);
if (fclose(score) == EOF) {
fprintf(stderr, "Unable to close score file\n");
return EXIT_FAILURE;
}
printf("Cya Later ! Thank's for participating! \n");
return EXIT_SUCCESS;
}
if (scanf("%lf%lf%lf", &x, &y, &z) != 3) { /* Checking to make sure correct input form */
fprintf(stderr, "Invalid Input.\n");
return EXIT_FAILURE; /* If wrong input, program exits */
}
if (mathMaster(c, x, y, z)) { /* If the user is correct , according to mathMaster function, then scores is increased */
scores++;
}
}
return EXIT_SUCCESS;
}