fork download
  1. #include <stdio.h>
  2.  
  3. float Square(int);
  4. float Cube(int);
  5. float Shrink(int);
  6. int main ()
  7. {
  8.  
  9. /* variable definition: */
  10. int intValue, menuSelect,
  11. float Results;
  12. intValue = 1;
  13.  
  14. // While a positive number
  15. while (intValue > 0)
  16. {
  17. printf ("Enter a positive Integer\n: ");
  18. scanf("%d", &intValue);
  19. if (intValue > 0)
  20. {
  21. printf ("Enter 1 to calculate Square, 2 to Calculate Cube \n: ");
  22. scanf("%d", &menuSelect);
  23. if (menuSelect == 1)
  24. {
  25. // Call the Square Function
  26. Results = Square(intValue);
  27. printf("Square of %d is %f\n",intValue,Results);
  28. }
  29. else if (menuSelect == 2)
  30. {
  31. // Call the Cube function
  32. Results = Cube(intValue);
  33. printf("Cube of %d is %f\n",intValue,Results);
  34. }
  35. else if (menuSelect == 3)
  36. {
  37. //call the shrink function
  38. Results = Shrink(intValue);
  39. printf("Half of %d is %f\n", intValue, Results);
  40. else
  41. printf("Invalid menu item, only 1, 2, or 3 is accepted\n");
  42. }
  43. }
  44. return 0;
  45. }
  46. /* function returning the Square of a number */
  47. int Square(int value)
  48. {
  49. return value*value;
  50. }
  51. /* function returning the Cube of a number */
  52. int Cube(int value)
  53. {
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
10
1
10
2
10
3
-99
compilation info
prog.c: In function ‘main’:
prog.c:11:1: error: expected identifier or ‘(’ before ‘float’
 float Results;
 ^~~~~
prog.c:26:1: error: ‘Results’ undeclared (first use in this function)
 Results = Square(intValue);
 ^~~~~~~
prog.c:26:1: note: each undeclared identifier is reported only once for each function it appears in
prog.c:40:1: error: expected ‘}’ before ‘else’
 else
 ^~~~
prog.c: At top level:
prog.c:47:5: error: conflicting types for ‘Square’
 int Square(int value)
     ^~~~~~
prog.c:3:7: note: previous declaration of ‘Square’ was here
 float Square(int);
       ^~~~~~
prog.c:52:5: error: conflicting types for ‘Cube’
 int Cube(int value)
     ^~~~
prog.c:4:7: note: previous declaration of ‘Cube’ was here
 float Cube(int);
       ^~~~
prog.c: In function ‘Cube’:
prog.c:53:1: error: expected declaration or statement at end of input
 {
 ^
prog.c:53:1: warning: control reaches end of non-void function [-Wreturn-type]
 {
 ^
stdout
Standard output is empty