fork download
  1. // C code
  2. // This program will provide options for a user to calculate the square,
  3. // cube, or multiple of 100 of a positive Integer input by a user.
  4. // Developer: Faculty CMIS102 User: Herman Sanchez
  5. // Date: April 29th, 2017
  6. #include <stdio.h>
  7. // Function prototypes
  8. int Square(int value);
  9. int Cube(int value);
  10. int Times(int value);
  11. int main ()
  12. {
  13. /* variable definition: */
  14. int intValue,menuSelect,Results;
  15. intValue = 1;
  16. // While a positive number
  17. while (intValue > 0)
  18. {
  19. printf ("Enter a positive Integer\n: ");
  20. scanf("%d", &intValue);
  21. if (intValue > 0)
  22. {
  23. printf ("Enter 1 to calculate Square, 2 to Calculate Cube, 3 to multiply by 100\n: ");
  24. scanf("%d", &menuSelect);
  25. if (menuSelect == 1)
  26. {
  27. // Call the Square Function
  28. Results = Square(intValue);
  29. printf("Square of %d is %d\n",intValue,Results);
  30. }
  31. else if (menuSelect == 2)
  32. {
  33. // Call the Cube function
  34. Results = Cube(intValue);
  35. printf("Cube of %d is %d\n",intValue,Results);
  36. }
  37. else if (menuSelect == 3)
  38. {
  39. // Call the Times100 function
  40. Results = Times(intValue);
  41. printf("%d times 100 is %d\n",intValue,Results);
  42.  
  43. }
  44. }
  45. else printf("Invalid menu item, only 1, 2, or 3 is accepted\n");
  46. }
  47. return 0;
  48. }
  49. /* function returning the Square of a number */
  50. int Square(int value)
  51. {
  52. return value*value;
  53. }
  54. /* function returning the Cube of a number */
  55. int Cube(int value)
  56. {
  57. return value*value*value;
  58. }
  59. /* function returning the value times 100*/
  60. int Times(int value)
  61. {
  62. return value * 100;
  63. }
Success #stdin #stdout 0s 9432KB
stdin
12
1
12
2
12
3
-1
stdout
Enter a positive Integer
: Enter 1 to calculate Square, 2 to Calculate Cube, 3 to multiply by 100
: Square of 12 is 144
Enter a positive Integer
: Enter 1 to calculate Square, 2 to Calculate Cube, 3 to multiply by 100
: Cube of 12 is 1728
Enter a positive Integer
: Enter 1 to calculate Square, 2 to Calculate Cube, 3 to multiply by 100
: 12 times 100 is 1200
Enter a positive Integer
: Invalid menu item, only 1, 2, or 3 is accepted