Need help on a painter program

So I wrote this program in visual studio that has you input number of rooms and the sqft of walls for those rooms and then it tells you the cost and hours it will take.

I have a few issues.

1) I need a way to have the user input actually show the number of rooms I selected. For example, no matter what number of rooms I type in, it will still always ask for sqft of 4 rooms. I want it to ask for the amount I enter.

2) My formula kinda doesn't make sense, but still gives me an answer that is close to the correct one, basically, it should take 1 hour per 24.2sqft and the price should be $58.13 per hour. How can I fix this in my math functions and in main?

#include "stdafx.h"
#include <iostream>

using namespace std;


//PROTOTYPES
void showMenu(int &);
int numRooms();
float wallArea();
float laborHrs(float);
void showCost(float);


int main()
{
int choice;

showMenu(choice);

while (choice == 1)
{
numRooms();
float total = wallArea();
float hours = laborHrs(total);
showCost(hours);
cout << endl;
showMenu(choice);
}

if (choice == 2)
{
exit(0);
}


system("pause");
return 0;
}


//FUNCTIONS

// simple menu to keep loop going or to quit
void showMenu(int &choice)
{
cout << "Do Painter Function" << endl;
cout << "1. Get Labor Estimate" << endl;
cout << "2. Quit" << endl;
cout << "Enter your choice: ";
cin >> choice;

while (choice < 1 || choice > 2)
{
cout << "Please enter 1 or 2: ";
cin >> choice;
}
}

// asks user for number of rooms
int numRooms()
{
int rooms;
cout << "Please enter the number of rooms to be painted: ";
cin >> rooms;
return rooms;
}

// adds sqft of all rooms
float wallArea()
{
float room1, room2, room3, room4, total;
cout << "Please enter the wall space area for room #1: ";
cin >> room1;
cout << "Please enter the wall space area for room #1: ";
cin >> room2;
cout << "Please enter the wall space area for room #1: ";
cin >> room3;
cout << "Please enter the wall space area for room #1: ";
cin >> room4;
total = room1 + room2 + room3 + room4;
return total;
}

// calculates labor time in hours
float laborHrs(float hours)
{
float labor;
labor = (hours / 60) * 5;
cout << "Hours of labor: " << labor << " hrs." << endl;
return labor;
}

// calculates cost of labor
void showCost(float labor)
{
float laborCost;
laborCost = (labor * 58.13);
cout << "Cost of labor: $" << laborCost << endl;
}
I'm not actually sure I know what you mean by 1). But I have a question about your code. You call a function that asks the user the enter the number of rooms, but it seems that that value is unused throughout the code. I'm guessing that you were going to include it in the wallArea() function.

This is a little tip for the future... just my opinion so you don't have to listen to this.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
float hours = laborHrs(total);//you send in total
showCost(hours);//you send in hours

// calculates labor time in hours
float laborHrs(float hours) //You sent in total but your variable name is hours
{
float labor;
labor = (hours / 60) * 5;
cout << "Hours of labor: " << labor << " hrs." << endl;
return labor;
}

// calculates cost of labor
void showCost(float labor) //You sent in hours but variable name is labor
{
float laborCost;
laborCost = (labor * 58.13);
cout << "Cost of labor: $" << laborCost << endl;
}
I think that it will be easier for you to see what is actually happening if you have have a corresponding and meaningful name for a variable. Or using comments might help you.
What I mean is something like this:
1
2
3
4
5
6
7
float laborHrs(float totArea)
{
float hours;
hours = (totArea/60)*5;
cout << "Hours of labor: " << labor << " hrs." << endl;
return hours;
}

Note: I didn't fix anything in the code, I just made it look more understandable in my opinion.

On a separate note, I believe that you have a problem with calculating your hours of labor. You might want to re-read how the hours of labor is calculated in your problem.
I figured out my second question, but need help using my number of rooms in my wallAread() function.

I input 5 for example for number of rooms but then it asks me to input the amount of sqft for each room. Its only giving me 4 rooms, how do I make it so it will do as many as I ask.

Do you understand??

This needs to change to be able to adapt to how many rooms I ask:

float wallArea()
{
float room1, room2, room3, room4, total;
cout << "Please enter the wall space area for room #1: ";
cin >> room1;
cout << "Please enter the wall space area for room #1: ";
cin >> room2;
cout << "Please enter the wall space area for room #1: ";
cin >> room3;
cout << "Please enter the wall space area for room #1: ";
cin >> room4;
total = room1 + room2 + room3 + room4;
return total;
}
Last edited on
I see what you mean. I don't want to tell you too much because I want you to figure this out. But what you can do is implement an array for the 5 float variables.

It might be more understandable if you change wall1, wall2, wall3, wall4, totArea instead. Again my opinion you don't have to implement the name.

You can set up an algorithm that loops until you reach the number of rooms the user inputted.

something like this
1
2
float wall1[numRoom]; //numRoom = the number of rooms user inputted
//If you haven't learned arrays then maybe this isn't the method 
Last edited on
My problem is being able to have the string:

cout << "Please enter the wall space area for room #1: ";

change everytime I add one so they all don't show up as room #1 and keep going up a number.
I think you should give it some more thought. Hint: What can the program manipulate?
Topic archived. No new replies allowed.