Please help in Language C A carpeting company wants to estimate what it will cos
ID: 3813039 • Letter: P
Question
Please help in Language C
A carpeting company wants to estimate what it will cost a customer to have a room carpeted. They can carpet
65 sq. ft. of room space in 4 hours, and they charge $25.00 per hour as their labor rate.
Write a program to ask the user for the length of the room (in inches) to be carpeted, the width of the room (in inches) to be carpeted, and the price of a square foot of carpeting. For both the length and width, make sure the number entered is a non-zero positive number, and continue to ask the user for the value until a valid number is entered. For the price of a square foot of carpeting, make sure that the price is between $1.00 and $10.00 inclusive, and continue to ask for the price until a valid number is entered. Then, using 5 different functions, calculate The square footage of the room The number of hours required to carpet the room The price for the carpet to cover the room The labor charges to carpet the room The total cost to carpet the room Create global constants for: The number of square feet that can be carpeted in 4 hours (65) The number of hours required to carpet 65 sq. ft. (4) The labor rate (25.00) The minimum carpet price (1.00) The maximum carpet price (10.00) Any other numbers used in your program The program will display: The square footage of the room The number of hours to carpet the room The price for the carpet The labor charges The total cost to carpet the roomExplanation / Answer
Here is your program in C:
#include <stdio.h>
#define SQFEETIN4HOURS 65.0
#define NUMOFHOURSTOCARPET65 4.0
#define LABOR_RATE 25.00
#define MIN_CARPET_PRICE 1.00
#define MAX_CARPET_PRICE 10.00
double convertTofoot(double x) {
return x/12.0;
}
double getSquareFootageOfRoom(double length,double width) {
double len = convertTofoot(length);
double wid = convertTofoot(width);
return len*wid;
}
double getHoursToCarpetRoom(double carpetArea) {
return (carpetArea*NUMOFHOURSTOCARPET65)/SQFEETIN4HOURS;
}
double totalCarpetPrice(double carpetArea,double pricePerSqFoot) {
return carpetArea*pricePerSqFoot;
}
double totalLaborCharges(double totalHoursSpent) {
return totalHoursSpent*LABOR_RATE;
}
double totalCost(double carpetPrice,double totalLaborCharges){
return carpetPrice+totalLaborCharges;
}
int main(void) {
// your code goes here
double length = 0.0;
double width = 0.0;
double pricePerSqFoot = 0.0;
do {
printf("Please Enter a valid room length(in inches) :");
scanf("%lf",&length);
} while( length <= 0.0 );
do {
printf("Please Enter a valid room width(in inches) :");
scanf("%lf",&width);
} while( width <= 0.0 );
do {
printf("Please Enter a valid carpet price per square foot :");
scanf("%lf",&pricePerSqFoot);
} while( pricePerSqFoot < MIN_CARPET_PRICE || pricePerSqFoot > MAX_CARPET_PRICE);
double sqFtroom = getSquareFootageOfRoom(length,width);
double numOfHourSpent = getHoursToCarpetRoom(sqFtroom);
double carpetPrice = totalCarpetPrice(sqFtroom,pricePerSqFoot);
double laborCharges = totalLaborCharges(numOfHourSpent);
printf("The square footage of the room is %.2lf sq.ft ",sqFtroom);
printf("Number of hours spent to carpet the room is %.2lf hours ",numOfHourSpent);
printf("Total price for the carpet is $%.2lf ",carpetPrice);
printf("Total labor charges for the carpet is $%.2lf ",laborCharges);
printf("Total cost to carpet the room is $%.2lf ",totalCost(carpetPrice,laborCharges));
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.