With the inputs 5, 6, 14, and 4.5, the result should be 374 but i keep getting 4200774. What do i need to fix
Code:
#include <stdio.h>
#define PI 3.141592654
int main()
{
int layers, radius_top, radius_bottom, feed, y;
float cake, x, lay_area;
printf("How many layers will your cake have? \n");
scanf("%d", &layers);
printf("What is the radius of the top layer?\n");
scanf("%d", &radius_top);
printf("What is the radius of the bottom layer?\n");
scanf("%d", &radius_bottom);
printf("How much cake in cross-sectional area does each guest need?\n");
scanf("%f", &cake);
x = (radius_bottom - radius_top) / (layers - 1);
for (y = layers; y > 0; y--)
{ lay_area = (radius_top * radius_top) * PI;
feed += lay_area / cake;
radius_top += x; }
printf("Your cake will feed %d guests.", feed);
return 0;
}