Should I change something in written code? Compiler says that everything is right — no errors or warnings.
- You are building a new home and you have calculated exactly how much cement you need for the foundation.
- Ideally you'd like to purchase this exact amount of cement, but the store only sells cement in 120-pound bags.
- Each of these bags costs 45 dollars.
Please write a C program that calculates the cost of the cement you will have to purchase to build your foundation.
- Your program should first read a decimal number representing the amount of cement needed (in pounds) for the foundations of your new home.
- Your program should then display the total cost of the cement bags you have to purchase to have enough cement to build your foundation.
- To make your program simpler, you are guaranteed that the amount of cement needed will NEVER be a multiple of 120.
My code so far:
#include <stdio.h>
#include <math.h>
int main(void) {
int price=45, totalPrice, OneBag=120;
float needed;
do
{
printf("Enter the amount of cement you need for your foundation that is not dividable by 120: ");
scanf("%f", &needed);
} while (fmodf(needed, OneBag)==0);
totalPrice = ((int)needed/OneBag+1)*(price);
printf("Total cost of cement you will need for your foundation is %d", totalPrice);
return 0;
}