1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "mathMaster.h"
  4.  
  5. int main() {
  6. FILE *score;
  7. double x;
  8. double y;
  9. double z;
  10. int c;
  11. int scores;
  12. scores = 0;
  13. while (1) {
  14. printf(
  15. "Enter 's' to input two double values, and the sum of these values: \n");
  16.  
  17. printf(
  18. "Enter 'p' to input two double values, and the product of these values: \n");
  19.  
  20. printf(
  21. "Enter 'd' to input two double values, and the difference of these values: \n");
  22.  
  23. printf(
  24. "Enter 'm' to input two double values, and the maximum of these values: \n");
  25.  
  26. printf(
  27. "Enter 'n' to input two double values, and the minimum of these values: \n");
  28.  
  29. printf("Enter 'q' to quit.\n");
  30. c = getchar();
  31. while (getchar() != '\n') {
  32. ;
  33. }
  34. if ((c == 'q') || (c == 'Q')) { /* Checking if user chose to quit program */
  35. if ((score = fopen("a4.score", "r")) != NULL) {
  36. fprintf(stderr,
  37. "Score file exists, would you like to overwrite? (Y/N)\n ");
  38. c = getchar();
  39. }
  40. while (getchar() != '\n') {
  41. ;
  42. }
  43.  
  44. if (fclose(score) == EOF) {
  45. fprintf(stderr, "File cannot close properly\n");
  46. return EXIT_FAILURE;
  47. }
  48.  
  49. if (!(c == 'y' || c == 'Y')) {
  50. fprintf(stderr,
  51. "Leaving score file untouched, terminating program.\n");
  52. return EXIT_SUCCESS;
  53. }
  54.  
  55. if ((score = fopen("a4.score", "w")) == NULL) {
  56. fprintf(stderr, "Cannot open scores. \n");
  57. return EXIT_FAILURE;
  58. }
  59.  
  60. fprintf(score, "Your score is: %d", scores);
  61.  
  62. if (fclose(score) == EOF) {
  63. fprintf(stderr, "Unable to close score file\n");
  64. return EXIT_FAILURE;
  65. }
  66.  
  67. printf("Cya Later ! Thank's for participating! \n");
  68. return EXIT_SUCCESS;
  69. }
  70.  
  71. if (scanf("%lf%lf%lf", &x, &y, &z) != 3) { /* Checking to make sure correct input form */
  72. fprintf(stderr, "Invalid Input.\n");
  73. return EXIT_FAILURE; /* If wrong input, program exits */
  74. }
  75.  
  76. if (mathMaster(c, x, y, z)) { /* If the user is correct , according to mathMaster function, then scores is increased */
  77. scores++;
  78. }
  79. }
  80. return EXIT_SUCCESS;
  81. }
  82.  
  83.