Hello,
My name is Brandon. I'm new to programming, and I just started a course at college where I must write a C program. The only other program I've written was the helloworld program. I am having trouble completing my first assignment. I have tried for hours to get it to work properly, but im getting errors, and strange outputs. Basically, I am to write an app that helps estimate how much it would cost to paint a room. here is the description the teacher gave me:

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.

here is the code I've already written:
Code:
```main() { /*Written by Brandon Benyacar*/

int area, labour, length, width, height=8, ceiling, setup=100, paint;
float total, room=;

{printf("Painting Cost Estimator \n Enter length of room in feet: \n"); /*prompt user to input values*/
scanf("%d", &length);
printf("Enter width of room in feet: \n ");
scanf("%d", &width);
printf("Please select grade of paint to use for walls: \n 1 - Basic \n 2 - Regular \n 3 - Premium \n");
scanf("%d", &paint);
if(paint<=0 || paint>3) printf("Please select a grade of paint that actually exists!!! \n");
printf("Enter if ceiling is to be painted: \n 1 Yes \n 2 No \n");
scanf("%d", &ceiling);}

{if(ceiling==1 &ceiling=(length*width)); /* Define whether ceiling is to be included in cost*/
if(ceiling==2 &ceiling=0);}

{if(paint==1 &paint=20);    /*assign cost to paint*/
if(paint==2 &paint=30);
if(paint==3 &paint=40);}

{area=(2*length*height)+(2*width*height)+ceiling;
printf("%d sq.feet \n", area);}
room=((area400)*paint);
printf ("Total %d", room);
}```
I realise I am nowhere near complete, but I wanted to make sure I got rid of any errors now before I continue.

2. && means "that thing there and this thing here..."
& means bitwise and (the bits in this and that that are both set)
= means assign a value to a thing
== means compare a value to another value
; after an if statement typically means you made a mistake.

Now look at what you have:
Code:
`if(paint==1 &paint=20);`
You should turn on your compiler's warnings.
Code:
`room=((area400)*paint);`
What is that supposed to be? As it is, it think you have a variable named area400.

Quzah.

3. I believe that's a typo; I think the OP wants area divided by 400, judging from the question.

4. ok, I have made a typo for area400, it was supposed to be value of area divided by 400. Paint I can now see is wrong, but im still not sure how to fix it. as is, the problems im running into are ceiling, gives me the same sq.foot whether I select to paint it or not, and the error message which is supposed to loop doesnt, and im not sure how to make it.

5. You have a ton of problems with your code. Fix up all the stuff I mentioned, and then post your code. Also, your indentation is terrible, and you keep using random pairs of braces where you don't need them - which isn't technically wrong, it's just not necessary.

Quzah.

6. I know my code is wrong, and I would fix up everything, but I dont know how. I learn best from example. thats why I'm asking for help :P
please forgive my poor indentation and random brackets, I'm still just learning. I will try to fix as much as I can by myself in the meantime

7. I've already given examples of what is wrong. What do you mean to be happening here:
Code:
`if(paint==1 &paint=20);`
if paint is one then make paint 20?
Code:
```if( paint == 1 )
paint = 20;```
You may also want to look into the else keyword:
Code:
```if( paint == 1 )
paint = 20;
else
if( paint == 2 )
paint = 30;
else
if( paint == 3 )
paint = 40;
else
... you entered the wrong thing```
Quzah.

8. thanks, that is better. now how can I get the error to loop back to ask the user the same question again? I know I need while, but am unsure how to implement it

9. Originally Posted by Bx2
thanks, that is better. now how can I get the error to loop back to ask the user the same question again? I know I need while, but am unsure how to implement it
You can use a while loop, where the condition is the user input. i.e., loop while user input is not equal to 'q' or whatever the user is supposed to enter to quite the calculations.

10. okay, so I've been messing around with the code, and I still cant get the hang of the do while loop. can anybody explain to me exactly what I'm doing wrong? also the total always equals \$0. here is my current code:
Code:
```main() { /*Written by Brandon Benyacar*/

int area, labour, length, width, height=8, ceiling, setup=100, paint;
float total, room;

{printf("Painting Cost Estimator \n Enter length of room in feet: \n"); /*prompt user to input values*/
scanf("%d", &length);
printf("Enter width of room in feet: \n ");
scanf("%d", &width);}

{{		printf("Please select grade of paint to use for walls: \n 1 - Basic \n 2 - Regular \n 3 - Premium \n"); /*assign cost to paint*/
scanf ( "%d", &paint );

if( paint == 1 )
paint = 20;
else
if( paint == 2 )
paint = 30;
else
if( paint == 3 )
paint = 40;

else
while ( paint <= 0 || paint > 3 );	}

{ printf("Enter if ceiling is to be painted: \n 1 Yes \n 2 No \n");  /* Define whether ceiling is to be included in cost*/
scanf("%d", &ceiling);
while ( ceiling = 0 || ceiling > 2 );
if( ceiling == 1 )
ceiling = (length*width);
else
if( ceiling == 2 )
ceiling = 0;
else
printf ("You made an incorrect selection. Please choose whether the ceiling is to be painted: \n");}

{area=(2*length*height)+(2*width*height)+ceiling;
printf("%d sq.feet \n", area);}

{labour=(area/200)*2;
room=((area)*paint)*2;
total=room+setup+labour;
printf ("Total: \$%d \n", total);
}
}```
keep in mind ive been messing around with the code so not every little detail will be exactly as intended.

11. \$ gcc -Wall bar.c
bar.c:3: warning: return type defaults to ‘int’
bar.c: In function ‘main’:
bar.c:35: warning: suggest parentheses around assignment used as truth value
bar.c:50: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘double’
bar.c:52: warning: control reaches end of non-void function

Line 35
while ( ceiling = 0 || ceiling > 2 );

Line 50
printf ("Total: \$%d \n", total);

12. good evening folks. I've learned a lot from this page. However I was wondering if someone could lend me a hand as well. I've been assigned the same question in my C Programming class and unfortunately the professor is unwilling to help (well says hes unable to).

in anycase I actually have the same thing in terms of how Brandon uses paint.

Code:
```         if( paint == 1 )
paint = 40;
else
if( paint == 2 )
paint = 30;
else
if( paint == 3 )
paint = 20;```
now my options are "1" is for Premium paint charged at 40 dollars
option "2" for Regular at 30 dollars
option "3" for Basic at 20 dollars

at the end of my program. I want to calculate the costs and totals.

so the results should look like this

RESULTS:
Total Area: 1382 sq ft
Regular paint cost: \$ 76.80
Basic paint cost: \$ 47.00
Labour costs: \$376.40
TOTAL COST: \$580.20

what i have so far is:

Code:
```{              area=(length*height)+ceiling;
printf("The total area is, %d sq.feet\n", area);
paint=
labour=(area/200)*2+setup;
printf("Labour cost: %d\n", labour);
room=(area*paint)*2;
printf("room total: %d\n", room);
total=room+labour;
printf ("Total: \$%d\n", total);}```

now my issue is that i am unsure on how to incorporate paint into the formula based on the choices of paint the client requested.

when i run my program my end result is

The total area is, 122 sq.feet
Labour cost: 100
Room total: 0
Total: \$0

now i think labour cost is wrong...because it says

"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"

so thats why in my formula i wrote
Labour=(area/200)*2+setup

divided by 200 for the per sq feet x 2 for the 2coats. 100 for the setup. I dont know where to add that "plus" 40. Im at a total loss lol.

And just as important, I dont know how to effectively make my questions loop until the user ends their selections for the totals :S.

apologies for the long post. Id greatly appreciate any help. I am using Matrix. And nled for writing up my program.

14. Originally Posted by CommonTater
sorry i figured since its literally the same assignment, i should just post here figured someone would say to me "theres already a topic about this use search function" or something if i posted a new topic about the same thing.

Should I still create my own or leave it since i already posted ? .