I made this very very simple program on xcode:
#include <stdio.h>
int main(void)
{
float fix;
float var;
float price;
int res;
printf("This BEP calculator uses this formula:");
printf("\nFixed Costs ÷ (Price - Variable Costs per unit) = Breakeven Point in Units\n\n");
printf("Input product costs: ");
scanf("%f",&price);
fflush(stdin);
printf("Input fixed costs: ");
scanf("%f",&fix);
fflush(stdin);
printf("Input variable costs per unit: ");
scanf("%f",&var);
fflush(stdin);
res = fix / (price - var);
printf("The break even point is roughly %d units\n",res);
printf("Thank you from using this program\n");
getchar();
return 0;
}
But every time it gets to the result the program automatically closes, ignoring getchar()
.
What's the problem?