Which will either square, cube or shrink an integer based off a menu selection. I can not seem to allow for a float to be the result of the shrink.
Every time I try to allow for a float I receive multiple errors.
The code that works with a basic integer is below, need something that returns a float result for the shrink in C.
#include
int main ()
{
/* variable definition: */
int intValue, menuSelect,Results;
intValue = 1;
// While a positive number
while (intValue > 0)
{
printf ("Enter a positive Integern: ");
scanf("%d", &intValue);
if (intValue > 0)
{
printf ("Enter 1 to calculate Square, 2 to Calculate Cube, Enter 3 to Calculate Shrink n: ");
scanf("%d", &menuSelect);
if (menuSelect == 1)
{
// Call the Square Function
Results = Square(intValue);
printf("Square of %d is %dn",intValue,Results);
}
else if (menuSelect == 2)
{
// Call the Cube function
Results = Cube(intValue);
printf("Cube of %d is %dn",intValue,Results);
}
else if (menuSelect == 3)
{
Results = Shrink(intValue);
printf("shrink of %d is %dn", intValue,Results);
}
else
printf("Invalid menu item, only 1 or 2 or 3 is acceptedn");
}
}
return 0;
}
/* function returning the Square of a number */
int Square(int value)
{
return value*value;
}
/* function returning the Cube of a number */
int Cube(int value)
{
return value*value*value;
}
int Shrink(int value)
{
return value*1/2;
}