fork(1) download
  1. /*
  2. Intro the variabels
  3. propmt the user to enter the integer being alculated.
  4. while value positive then.. (no negative)
  5. prompt user if 1 is swuare and cube is 2
  6. if menuselct ==1
  7. if menu slct==2
  8. if else :invalid meni item 1 or 2 only
  9. */
  10.  
  11. #include <stdio.h>
  12. int square (int value){
  13. return value*value;
  14. }
  15. int cube (int value){
  16. return value*value*value;
  17. }
  18.  
  19. int main(void) {
  20. int intvalue, menuselect, result;
  21. float shrinkresult;
  22. intvalue=1;
  23. while(intvalue>0){
  24. printf("enter a positive integer\n:");
  25. scanf("%d", &intvalue);
  26. if(intvalue>0){
  27. printf("enter 1 to calculate square or 3 to shrink square, 2 to calculate cube or 4 to shrink cube\n:");
  28. scanf("%d", &menuselect);
  29. if(menuselect==1){
  30. result=square(intvalue);
  31. printf("square of %d is %d\n", intvalue, result);
  32. }
  33. else if(menuselect==3){
  34. shrinkresult=(square(intvalue))/2;
  35. printf("the shrink value of the square is %.2f\n:", shrinkresult);
  36. }
  37. else if(menuselect==2){
  38. result=cube(intvalue);
  39. printf("cube of %d is %d\n", intvalue, result);
  40. }
  41. else if(menuselect==4){
  42. shrinkresult=(cube(intvalue))/2;
  43. printf("the shrink value of the cube is %.2f\n:", shrinkresult);
  44. }
  45. else{
  46. printf("invalid menu item, only 1 or 2 is accepted\n");
  47. }
  48.  
  49. }
  50.  
  51. }
  52. return 0;
  53. }
  54.  
Success #stdin #stdout 0s 2172KB
stdin
50
3
25
1
-67890
stdout
enter a positive integer
:enter 1 to calculate square or 3 to shrink square, 2 to calculate cube or 4 to shrink cube
:the shrink value of the square is 1250.00
:enter a positive integer
:enter 1 to calculate square or 3 to shrink square, 2 to calculate cube or 4 to shrink cube
:square of 25 is 625
enter a positive integer
: