fork(2) download
  1. #include <stdio.h>
  2. float enteredNumber;
  3. int numberOfLoop;
  4.  
  5. void addition(void);
  6. void subtraction(void);
  7. void multiplication(void);
  8. void division(void);
  9.  
  10. int main(void){ /* Start of the main function */
  11. char request;
  12.  
  13. printf("Please Enter the Sign Which Operation Do You Want:\n");
  14. printf("+ => Addition\n- => Subtraction\n* => Multiplication\n/ => Division");
  15. scanf("%c", &request); /* Give the value of the char type variable 'request' from the user */
  16.  
  17. switch (request){ /* Switch the variable named request to understand the selection. */
  18. case '+':
  19. addition();
  20. break;
  21. case '-':
  22. subtraction();
  23. break;
  24. case '*':
  25. multiplication();
  26. break;
  27. case '/':
  28. division();
  29. break;
  30. default: /* If the user entered an invalid char, print this message. */
  31. printf("The sign you entered was out of the list. Try Again.");
  32. } /* End of the switch-case */
  33.  
  34. return 0; /* main function returns 0 */
  35.  
  36. } /* End of the main function */
  37.  
  38.  
  39.  
  40. void addition(void){
  41. float additionResult = 0;
  42. printf("How many numbers do you want to add?: ");
  43. scanf("%d", &numberOfLoop);
  44. for(int start = 1; start<=numberOfLoop; start++){
  45. printf("Enter number %d", start);
  46. scanf("%f", &enteredNumber);
  47. additionResult += enteredNumber;
  48. }
  49. printf("The result is %f", additionResult);
  50. }
  51.  
  52. void subtraction(void){
  53. float subtractionResult;
  54. printf("Enter the main number which other numbers will be subtracted from: ");
  55. scanf("%f", &subtractionResult);
  56. printf("How many numbers do you want to subtract?: ");
  57. scanf("%d", &numberOfLoop);
  58. for(int start = 1; start<=numberOfLoop; start++){
  59. printf("Enter number %d", start);
  60. scanf("%f", &enteredNumber);
  61. subtractionResult -= enteredNumber;
  62. }
  63. printf("The result is %f", subtractionResult);
  64. }
  65.  
  66. void multiplication(void){
  67. float multiplicationResult = 1;
  68. printf("How many numbers do you want to multiply?: ");
  69. scanf("%d", &numberOfLoop);
  70. for(int start = 1; start<=numberOfLoop; start++){
  71. printf("Enter number %d", start);
  72. scanf("%f", &enteredNumber);
  73. multiplicationResult *= enteredNumber;
  74. }
  75. printf("The result is %f", multiplicationResult);
  76. }
  77.  
  78. void division(void){
  79. float divisionResult;
  80. printf("Enter the Divided Number: ");
  81. scanf("%f", &divisionResult);
  82. printf("How many numbers do you want to divide?: ");
  83. scanf("%d", &numberOfLoop);
  84. for(int start = 1; start<=numberOfLoop; start++){
  85. printf("Enter number %d", start);
  86. scanf("%f", &enteredNumber);
  87. if (enteredNumber==0){
  88. printf("Error: You cannot divide number by zero! Try Again!");
  89. break;
  90. }
  91. divisionResult /= enteredNumber;
  92. }
  93. printf("The result is %f", divisionResult);
  94. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty