fork(1) download
  1. //code
  2. // This program will provide options for a user to calculate the square
  3. // cube or Shrink of a positive Integer or float input by a user.
  4. // Developer: Phillip Mobley/Faculty CMIS102
  5. // Date: Feb 22, 2018
  6.  
  7. #include <stdio.h>
  8.  
  9. float Square(float value);
  10. float Pie(float value);
  11. float Shrink(float value);
  12. int main ()
  13. {
  14. /* variable definition: */
  15. int menuSelect;
  16. float intValue, Results;
  17. intValue = 1;
  18.  
  19. // While a positive number
  20. while (intValue > 0)
  21. {
  22. printf ("Enter a positive Integer or float to be calculated \n: ");
  23.  
  24. scanf("%f", &intValue);
  25.  
  26. if (intValue > 0)
  27. {
  28. printf ("Enter 1 to calculate Square, 2 to multiply squared integer by Pie, 3 to calculate shrink \n: ");
  29. scanf("%d", &menuSelect);
  30. if (menuSelect == 1)
  31. {
  32. // Call the Square Function
  33. Results = Square(intValue);
  34. printf("Square of %f is %f\n",intValue,Results);
  35. }
  36. else if (menuSelect == 2)
  37. {
  38. // Call the Pie function
  39. Results = Pie(intValue);
  40. printf("(%f)^2 multiplied by Pie is %.2f\n",intValue,Results);
  41. }
  42. else if (menuSelect == 3)
  43. {
  44. // Call the Shrink function
  45. Results = Shrink(intValue);
  46. printf("Shrink of %f is %.2f\n",intValue,Results);
  47. }
  48. else
  49. printf("Invalid menu item, only 1, 2 or 3 is accepted\n");
  50. }
  51. }
  52.  
  53. return 0;
  54.  
  55. }
  56. /* function returning the Square of a number */
  57. float Square(float value)
  58. {
  59. return value*value;
  60. }
  61. /* function returning integer multiplied by Pie */
  62. float Pie(float value)
  63. {
  64. return (value*value)* 3.14;
  65. }
  66. /* function returning the Shrink of a number */
  67. float Shrink(float value)
  68. {
  69. return value/4;
  70. }
Success #stdin #stdout 0s 4260KB
stdin
10
1
10
2
86
3
-1
stdout
Enter a positive Integer or float to be calculated 
: Enter 1 to calculate Square, 2 to multiply squared integer by Pie, 3 to calculate shrink 
: Square of 10.000000 is 100.000000
Enter a positive Integer or float to be calculated 
: Enter 1 to calculate Square, 2 to multiply squared integer by Pie, 3 to calculate shrink 
: (10.000000)^2 multiplied by Pie is 314.00
Enter a positive Integer or float to be calculated 
: Enter 1 to calculate Square, 2 to multiply squared integer by Pie, 3 to calculate shrink 
: Shrink of 86.000000 is 21.50
Enter a positive Integer or float to be calculated 
: