Carpet Job Program A carpeting company wants to estimate what it will cost a cus
ID: 3706131 • Letter: C
Question
Carpet Job Program
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 and return:
• 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 programThe 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 room
Hints:
• Validation error messages are indented 3 spaces • Have a blank line between the inputs and the output
• Functions, just as the main() program, should have comments
• Value-returning functions should not get input or display output
• Inches (or square inches) will have to be converted to feet (or square feet)
• To calculate the labor hours you will need to know how many square feet can be carpeted in 1 hour (DO NOT pre-calculate the number of square feet that can be carpeted in 1 hour – use the 2 constants (of 65 and 4) and let the program calculate the number (in case a team of installers is hired that can carpet more than 65 square feet in 4 hours))
• Watch out for integer division
• Don’t forget the function prototypes (if necessary)
• Don’t forget the blank line before ‘Press any key to continue…”
Example Run #1:
(bold type is what is entered by the user)
Enter the length of the room (in inches): 144
Enter the width of the room (in inches): 120
Enter the price per sq. ft. of the carpet: $2.95
The square footage of the room is: 120.00 sq. ft.
The number of hours required to carpet 120.00 square feet is: 7.38 hours
The price for the carpet is: $354.00
The labor charges are: $184.62
The total cost to carpet the room is: $538.62
Example Run #2:
Enter the length of the room (in inches): -144
A positive value for the length must be entered.
Please re-enter the length of the room (in inches): 144
Enter the width of the room (in inches): 120
Enter the price per sq. ft. of the carpet: $2.95
The square footage of the room is: 120.00 sq. ft.
The number of hours required to carpet 120.00 square feet is: 7.38 hours
The price for the carpet is: $354.00
The labor charges are: $184.62
The total cost to carpet the room is: $538.62
Example Run #3:
Enter the length of the room (in inches): 144
Enter the width of the room (in inches): 120
Enter the price per sq. ft. of the carpet: $12.95
The price of the carpet must be between $1.00 and $10.00 inclusive.
Please re-enter the price per sq. ft. of the carpet: $2.95
he square footage of the room is: 120.00 sq. ft.
The number of hours required to carpet 120.00 square feet is: 7.38 hours
The price for the carpet is: $354.00
The labor charges are: $184.62
The total cost to carpet the room is: $538.62
The example runs show EXACTLY how your program input and output will look. (validation messages are indented 3 spaces)
Please write in C, with printf and scanf statements. Use While loops where needed and please use the 2 constants (of 65 and 4). Thanks
Explanation / Answer
#include <stdio.h>
#include<math.h>
#define LABOURRATE 25.00
#define MIN 1.00
#define MAX 10.00
#define X 65
#define Y 4
float sqfoot(float len, float wid){ //calculating the square footage of the room
return len*wid;
}
float time(float a){ // time require for carpeting for a given sq foot
return a*Y/X;
}
float price(float a, float p1){ // carpeting price
return a*p1;
}
float labcharges(float t) //labor price
{
return t*LABOURRATE;
}
float cost(float p2, float lc){ //total cost for carpeting
return p2+lc;
}
void main(){
float l,w; //length and width
float a,p1,t,p2,lc,total;
char c;
printf("Enter the length of the room(in inches):");
scanf("%f",&l);
while(l<0){
printf("A positive value for the length must be entered. Please re-enter the length of the room (in inches):");
scanf("%f",&l);
}
printf("Enter the width of the room(in inches):");
scanf("%f",&w);
while(w<0){
printf("A positive value for the width must be entered. Please re-enter the width of the room (in inches):");
scanf("%f",&w);
}
l=l/12; //converting length and width to feet
w=w/12;
printf("Enter the price per sq. ft. of the carpet:");
scanf("%f",&p1);
while(!(p1>=1 && p1<=10))
{
printf("The price of the carpet must be between $1.00 and $10.00 inclusive. Please re-enter the price per sq. ft. of the carpet: ");
scanf("%f",&p1);
}
a=sqfoot(l,w);
printf("The square footage of the room is:%.2f sq ft",a);
t=time(a);
printf(" The number of hours required to carpet 120.00 square feet is:%.2f hours",t);
p2=price(a,p1);
printf(" The price for the carpet is:$%.2f",p2);
lc=labcharges(t);
printf(" The labor charges are:$%.2f",lc);
total=cost(p2,lc);
printf(" The total cost to carpet the room is:$%.2f",total);
}