fork download
  1. #include <stdio.h>
  2. int Square(int value);
  3. int Cube(int value);
  4. int Shrink (int value);
  5. int main ()
  6. {
  7. /* variable definition: */
  8. int intValue, menuSelect,Results;
  9. intValue = 1;
  10. // While a positive number
  11. while (intValue > 0)
  12. {
  13. printf ("Enter a positive Integer\n: ");
  14. scanf("%d", &intValue);
  15. {
  16. printf ("Enter 1 to calculate Square, 2 to Calculate Cube, 3 to Calculate Shrink \n: ");
  17. scanf("%d", &menuSelect);
  18. if (menuSelect == 1)
  19. {
  20. // Call the Square Function
  21. Results = Square(intValue);
  22. printf("Square of %d is %d\n",intValue,Results);
  23. }
  24. else if (menuSelect == 2)
  25. {
  26. // Call the Cube function
  27. Results = Cube(intValue);
  28. printf("Cube of %d is %d\n",intValue,Results);
  29. }
  30. else if (menuSelect == 3)
  31. {
  32. // Call the Shrink function
  33. Results = Shrink(intValue);
  34. printf("Shrink of %d is %d\n",intValue,Results);
  35. }
  36. else
  37. printf("Invalid menu item, only 1, 2, or 3 is accepted\n");
  38. }
  39. }
  40. return 0;
  41. }
  42. /* function returning the Square of a number */
  43. int Square(int value)
  44. {
  45. return value*value;
  46. }
  47. /* function returning the Cube of a number */
  48. int Cube(int value)
  49. {
  50. return value*value*value;
  51. }
  52. /* function returning the Shrink of a number */
  53. int Shrink( int value)
  54. {
  55. return value*.5;
  56. }
  57.  
Success #stdin #stdout 0s 2172KB
stdin
1000
1
1000
2
-1000
3
4000
stdout
Enter a positive Integer
: Enter 1 to calculate Square, 2 to Calculate Cube, 3 to Calculate Shrink 
: Square of 1000 is 1000000
Enter a positive Integer
: Enter 1 to calculate Square, 2 to Calculate Cube, 3 to Calculate Shrink 
: Cube of 1000 is 1000000000
Enter a positive Integer
: Enter 1 to calculate Square, 2 to Calculate Cube, 3 to Calculate Shrink 
: Shrink of -1000 is -500