hi all, I'm new to C programming, first year in school and have hit a little snag in one of my assignments.
This is the program I have right now
Code:
#include <stdio.h>
int main() {
int length, width, quality, ceiling, area; /* declares variables */
/* initializes variables */
float premium = 0.00;
float regular = 0.00;
float basic = 0.00;
float labour = 100.00;
double total = 0.00;
printf("PAINTING COST ESTIMATOR \n");
printf("----------------------------------- \n");
/* do while loop which asks for length of room in feet and keeps going
until a positive value greater than 0 is entered */
do {
printf("Enter length of room in feet: ");
scanf("%d", &length); /* stores value of length */
if (length <= 0){
printf("Error! Must be a positive value\n "); /* prints error message if value is less than or equal to 0 */
}
}while (length <= 0);
/* same as above except for length */
do {
printf("Enter width of room in feet: ");
scanf("%d", &width);
if (width <= 0){
printf("Error! Must be a positive value \n");
}
}while (width <= 0);
/* do while loop to determine quality of paint, 1, 2 or 3 */
do {
printf("Enter quality (1:premium, 2:regular, 3:basic): ");
scanf("%d", &quality);
if (quality <= 0 || quality > 3){
printf("Error! Quality must be between 1 and 3 \n");
}
}while (quality <= 0 || quality > 3); /* loop keeps going until value is equal to 1, 2 or 3 */
/* asks user if s/he wishes to paint ceiling by entering 1 or 2 */
do {
printf("Enter if ceiling to be painted (1:yes / 2:no): ");
scanf("%d",&ceiling);
if (ceiling <= 0 || ceiling >= 3){
printf("Error! Please enter 1 for Yes or 2 for No \n");
}
}while (ceiling <= 0 || ceiling >= 3);
printf("RESULTS: \n");
/* determines if user entered 1 or 2 for ceiling to be painted */
if (ceiling == 1 && area <= 400){
area = 2 * (length * 8) + 2 *(width * 8) + (length * width);/* determines square feet total */
printf("Total Area: %d \n", area); /* stores value of sq ft */
}else if (ceiling == 1 && area > 400){
area = 2 * (length * 8) + 2 *(width * 8) + (length * width);/* determines square feet total */
printf("Total Area: %d \n", area); /* stores value of sq ft */
}else if (ceiling == 2){
area = 2 * (length * 8) + 2 * (width * 8);/* determines sq ft total if ceiling is not included */
printf("Total Area :%d \n", area);
/* calculates total paint cost, determined by which quality of paint user entered */
}if (quality == 1 && area < 400){ /* determiens if quality is premium and area is less than 400 */
premium = 40.00 * 1; /* determines premium cost if if statement above is true */
printf("Premium paint cost: %.2f \n", premium); /* prints these if statement above is true */
printf("Regular paint cost: 0.00 \n");
printf("Basic paint cost: 0.00 \n");
}else if (quality == 1 && area >= 400){
premium = 40.00 * 2;
printf("Premium paint cost: %.2f \n", premium);
printf("Regular paint cost: 0.00 \n");
printf("Basic paint cost: 0.00 \n");
}else if (quality == 2 && area < 400) {
regular = 30.00 * 1;
printf("Premium paint cost: 0.00 \n");
printf("Regular paint cost: %.2f \n", regular);
printf("Basic paint cost: 0.00 \n");
}else if (quality == 2 && area >= 400){
regular = 30.00 * 2;
printf("Premium paint cost: 0.00 \n");
printf("Regular paint cost: %.2f \n", regular);
printf("Basic paint cost: 0.00 \n");
} else if (quality == 3 && area < 400) {
basic = basic + 20.00 * 1;
printf("Premium paint cost: 0.00 \n");
printf("Regular paint cost: 0.00 \n");
printf("Basic paint cost: %.2f \n", basic);
}else if (quality == 3 && area >= 400){
basic = basic + 20.00 * 2;
printf("Premium paint cost: 0.00 \n");
printf("Regular paint cost: 0.00 \n");
printf("Basic paint cost: %.2f \n", basic);
}
labour = labour + 40.00 * (area / 200); /* determines total labour costs and prints it */
printf("Labour Cost: %.3f \n", labour);
total = premium + regular + basic + labour; /* determines total cost and prints it */
printf("TOTAL COST: %.2f \n", total);
return 0;
}
now the question for the assignment is
You are to write a program to assist a painting contractor to prepare quotes for painting
jobs. The quotes are NOT to include HST. The painter always applies 2 coats of paint to
areas being painted. Painting costs depend on area to be painted and quality of paint to be
used. 1 or more rooms may be painted. You can assume all walls to be painted have a
height of 8 feet. Ceilings are painted using a basic grade of paint at $20 per 400 square
feet. Wall paint also covers 400 square feet and 3 qualities of wall paint are available;
premium at $40, regular at $30 and basic at $20. Labour costs include a setup cost of $100
plus $40 per 200 square feet (includes 2 coats) to be painted. Paint is obtained in bulk so
the quote is to only include paint used. An error message is to be displayed if any invalid
input is entered and input is to be prompted for and re-input until valid.
My output from the program is:
PAINTING COST ESTIMATOR
-----------------------------------
Enter length of room in feet: 15
Enter width of room in feet: 10
Enter quality (1remium, 2:regular, 3:basic): 2
Enter if ceiling to be painted (1:yes / 2:no): 1
RESULTS:
Total Area: 550
Premium paint cost: 0.00
Regular paint cost: 60.00
Basic paint cost: 0.00
Labour Cost: 180.000
TOTAL COST: 240.00
But I am supposed to get this :
PAINTING COST ESTIMATOR
Enter length of room in feet: 15
Enter width of room in feet: 10
Enter quality (1remium, 2:regular, 3:basic): 2
Enter if ceiling to be painted (1-yes / 2-no): 1
RESULTS:
Total Area: 550 sq ft
Premium paint cost: $ 0.00
Regular paint cost: $ 60.00
Basic paint cost: $ 15.00
Labour costs: $210.00
TOTAL COST: $285.00
What am I doing wrong can someone please help!!