fork download
  1. #include <stdio.h>
  2. // Function prototypes int Square(int value); int Cube(int value);
  3. int main ()
  4. {
  5. /* variable definition: */
  6. int intValue, menuSelect,Results;
  7. intValue = 1;
  8. // While a positive number
  9. while (intValue > 0)
  10. {
  11. printf ("Enter a positive Integer\n: ");
  12. scanf("%d", &intValue);
  13. //if (intValue > 0)
  14. {
  15. printf ("Enter 1 to calculate Square, 2 to Calculate Cube \n: ");
  16. scanf("%d", &menuSelect);
  17. printf ("menuSelect %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
  31. printf("Invalid menu item, only 1 or 2 is accepted\n");
  32. }
  33. }
  34. return 0;
  35. }
  36. /* function returning the Square of a number */
  37. int Square(int value)
  38. {
  39. return value*value;
  40. }
  41. /* function returning the Cube of a number */
  42. int Cube(int value)
  43. { return value*value*value;
  44. }
Success #stdin #stdout 0s 9432KB
stdin
10
1
10
2
-99
stdout
Enter a positive Integer
: Enter 1 to calculate Square, 2 to Calculate Cube 
: menuSelect 1 => Square of 10 is 100
Enter a positive Integer
: Enter 1 to calculate Square, 2 to Calculate Cube 
: menuSelect 2 => Cube of 10 is 1000
Enter a positive Integer
: Enter 1 to calculate Square, 2 to Calculate Cube 
: menuSelect 2 => Cube of -99 is -970299