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.

88 lines
3.2 KiB

  1. #include "displayMenuCalculator.h"
  2. #include "calculatorGetUserInput.h"
  3. #include "calculatorGetUserInputFactorial.h"
  4. #include "calculatorAdd.h"
  5. #include "calculatorSubtract.h"
  6. #include "calculatorMultiply.h"
  7. #include "calculatorDivide.h"
  8. #include "calculatorFactorial.h"
  9. // Note:
  10. /* This Function may or may not be implemented in actual program, even if it is merged to the main branch.
  11. If it is temporarily not included in the main Program, then this has a role in future Development of the Project */
  12. int operation1 = 1;
  13. int operation2 = 2;
  14. int operation3 = 3;
  15. int operation4 = 4;
  16. int operation5 = 5;
  17. int check()
  18. {
  19. const int rConst = 1; // RandomConstant created for indirectly testing void displayMenuCalculator()
  20. if(rConst == 1)// RandomConstant created for indirectly testing void displayMenuCalculator()
  21. {
  22. return 1;
  23. }
  24. }
  25. void displayMenuCalculator(char x) //Displays the correct output, only when x is c.
  26. {
  27. float num1, num2, answer; //Created for storing numbers for addition, subtraction, multiplication and division and the final answer.
  28. int num; //Created specially for calculatorFactorial()
  29. int choose;
  30. if(x == 'c') //calculator can be activated by adding 'c' in void displayMenuCalculator()
  31. {
  32. if(check() == 1)
  33. { //The Main Menu of the calculator
  34. printf(" %d. Add\n", operation1);
  35. printf(" %d. Subtract\n", operation2);
  36. printf(" %d. Multiply\n", operation3);
  37. printf(" %d. Divide\n", operation4);
  38. printf(" %d. Factorial\n", operation5);
  39. printf("Enter your choice: "); // Takes the choice of operations from the user
  40. scanf("%d", &choose); // Saves the choice
  41. switch (choose)
  42. { //takes user's choice and calls operation-functions accordingly
  43. case 1:
  44. calculatorGetUserInput(&num1, &num2);
  45. answer = calculatorAdd(num1, num2);
  46. printf("Answer: %f\n", answer);
  47. break;
  48. case 2:
  49. calculatorGetUserInput(&num1, &num2);
  50. answer = calculatorSubtract(num1, num2);
  51. printf("Answer: %f\n", answer);
  52. break;
  53. case 3:
  54. calculatorGetUserInput(&num1, &num2);
  55. answer = calculatorMultiply(num1, num2);
  56. printf("Answer: %f\n", answer);
  57. break;
  58. case 4:
  59. calculatorGetUserInput(&num1, &num2);
  60. answer = calculatorDivide(num1, num2);
  61. printf("Answer: %f\n", answer);
  62. break;
  63. case 5:
  64. calculatorGetUserInputFactorial(&num); //Created specially for factorial which gets a number from user.
  65. answer = calculatorFactorial(num);
  66. printf("Answer: %f\n", answer);
  67. break;
  68. default:
  69. printf("Invalid choice\n");
  70. return;
  71. }
  72. }
  73. }
  74. }