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