fork download
  1. // C code
  2. // This program will provide options for a user to calculate the square
  3. // or cube of a positive Integer input by a user.
  4. // Developer: Alexis Aragon
  5. // Date: Jun 30, 2016
  6.  
  7. #include <stdio.h>
  8. int main ()
  9.  
  10. {
  11.  
  12. /* variable definition: */
  13. int intValue, menuSelect,Results;
  14. intValue = 1;
  15.  
  16. {
  17. printf ("This is an additional function \n");
  18. }
  19.  
  20.  
  21. // While a positive number
  22. while (intValue > 0)
  23.  
  24.  
  25. {
  26.  
  27. printf ("Enter a positive Integer: \n ");
  28. scanf("%d", &intValue);
  29.  
  30. if (intValue > 0)
  31. {
  32.  
  33. printf ("Enter 1 to calculate Square, 2 to Calculate Cube: \n ");
  34. scanf("%d", &menuSelect);
  35.  
  36. if (menuSelect == 1)
  37. {
  38. // Call the Square Function
  39.  
  40. Results = Square(intValue);
  41. printf("Square of %d is %d\n",intValue,Results);
  42.  
  43. }
  44.  
  45. else if (menuSelect == 2)
  46.  
  47. {
  48.  
  49. // Call the Cube function
  50. Results = Cube(intValue);
  51. printf("Cube of %d is %d\n",intValue,Results);
  52.  
  53. }
  54.  
  55. else
  56.  
  57. printf("Invalid menu item, only 1 or 2 is accepted\n");
  58.  
  59. }
  60.  
  61. }
  62. return 0;
  63.  
  64. }
  65.  
  66. /* function returning the Square of a number */
  67. int Square(int value)
  68.  
  69. {
  70.  
  71. return value*value;
  72.  
  73. }
  74.  
  75. /* function returning the Cube of a number */
  76. int Cube(int value)
  77.  
  78. { return value*value*value;
  79.  
  80. }
Success #stdin #stdout 0s 2164KB
stdin
10
1
10
2
-99
stdout
This is an additional function 
Enter a positive Integer: 
 Enter 1 to calculate Square, 2 to Calculate Cube: 
 Square of 10 is 100
Enter a positive Integer: 
 Enter 1 to calculate Square, 2 to Calculate Cube: 
 Cube of 10 is 1000
Enter a positive Integer: