Hey everyone! The results of printing 'circle', switch case #3, comes out as a long negative number, although I'm sure the result should be positive. Am I overflowing? I've tried typecasting as double, long, etc, I can't seem to figure it out. Thanks!
Code:
int main(void)
{
int choice, x=0, square=0, cube=0, circle=0;
printf("Welcome to the Area Calculation Program.\n");
printf("(1)Square\n(2)Cubee\n(3)Circle\n");
printf("Please make a selection.\n");
scanf("%d", &choice);
while(choice<1 || choice>3)
{
printf("Incorrect choice. Please choose from the 3 options. \n");
scanf("%d", &choice);
}
switch(choice)
{
case 1:
printf("Please enter a positive number. \n");
scanf("%d", &x);
while(x<=0)
{
printf("Please enter a positive number.\n");
scanf("%d", &x);
}
square=x*x;
printf("The side length of the square is %d.\n", x);
printf("The area of the square is %d.\n", square);
break;
case 2:
printf("Please enter a positive number. \n");
scanf("%d", &x);
while(x<=0)
{
printf("Please enter a positive number.\n");
scanf("%d", &x);
}
cube=6*x*x;
printf("The side length of the cube is %d. \n", x);
printf("The area of the cube is %d. \n", cube);
break;
case 3:
printf("Please enter a positive number. \n");
scanf("%d", &x);
while(x<=0)
{
printf("Please enter a positive number. \n");
scanf("%d", &x);
}
circle=3.14159*x*x;
printf("The radius is %d\n", x);
printf("The area of the circle is %lf\n", circle);
break;
default:
printf("Please choose from the 3 options. \n");
scanf("%d", &choice);
break;
}
}