Hello nockson,
PLEASE ALWAYS USE CODE TAGS (the <> formatting button), to the right of this box, when posting code.
Along with the proper indenting it makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
http://www.cplusplus.com/articles/z13hAqkS/
Hint: You can edit your post, highlight your code and press the <> formatting button. This will not automatically indent your code. That part is up to you.
You can use the preview button at the bottom to see how it looks.
I found the second link to be the most help.
|
Posting the instructions for the program is very helpful, but I find that something like this helps to break it up into smaller steps to work on:
A painting company has determined that for every 8 square meters of wall space,
one liter of paint and 1.5 hours of labor will be required.
The company charges R55 per hour of labor.
You have been tasked to write a program that allows the user to enter the square meters of wall space
for a number of painting jobs and the price of the paint per litre used for each job.
The program should then display the following data for each job:
● The number of liters of paint required
● The hours of labor required
● The cost of the paint
● The labor charges
● The total cost of the paint job.
The program has the following functions:
● void inputAndValidate function that have two reference parameters,
namely one parameter for the wall space in square meters (thus of type double),
and the other for the price of the paint per liter (also of type double).
This function reads values from keyboard.
The function does not accept a value of less than R20 per litre for the price of the paint,
and it uses a do…while loop to display a message until the user enters a value greater than or equal
to R20 for the price of the paint per liter.
● void determineLabourAndPaint with three parameters:
one value parameter to supply the wall space;
and two reference parameters for the hours of labor and liters of paint required which should be returned to the main function.
ITCP112 – Take Home Assessment S1 2020 | V1.0 Page 5 of 5
● void determineCost with five parameters:
three value parameters to supply the hours of labor, liters of paint required and the price of the paint
per liter; and two reference parameters for the cost of the labor and the cost of the paint.
Remember that the company charges R55 per hour of labor.
|
Now you have a better idea of what needs done. Sorry about the indenting. Sometimes it does not indent well.
I am guessing that it could be a language problem, but in English "labour" is spelled "labor". Normally I do not change spelling, but this time I did. Not sure why.
When I read:
You have been tasked to write a program that allows the user to enter the square meters of wall space
for a number of painting jobs and the price of the paint per litre used for each job.
|
What I get from this is that a job is a building or address and each building has a number of rooms that need to be painted. If I have this wrong you will need to clarify this.
Next I would look at what you have so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include<iostream>
#include<iomanip>
using namespace std;
constexpr double LABOR_COST{ 55.0 };
constexpr double MIN_PAINT_COST{ 20.0 };
const double NR_JOBS = 6.0; // <--- Used correctly this can work for you.
void InputAndValidate(double& WallSpace, double& PaintPrice);
void determineLabourAndpaint(double WallSpace, double& hourslabour, double& paintrequired);
void determineCost(double hourslabour, double NumsPaintLiters, double Pricepaint, double& LabourCost, double& Costpaint);
int main()
{
//const double PRICE = 55;
double totalCost = 0.0;
double costPaint = 0.0;
double labourCharges = 0.0;
double hourslabour = 0.0;
double numsPainLliters = 0.0;
double wallSpace = 0.0;
double sqreMeters = 0.0;
double paintsPrice = 0.0;
cout << fixed << showpoint << setprecision(2);
cout << "Enter the square meters: ";
cin >> wallSpace;
cout << "Enter the price per liter: ";
cin >> paintsPrice;
determineLabourAndpaint(wallSpace, hourslabour, numsPainLliters);
int i = 1;
for (i = 1; i <= NR_JOBS; i++)
{
determineCost(hourslabour, numsPainLliters, paintsPrice, labourCharges, costPaint);
}
return 0; // <--- Not required, but makes a good break point.
}
void InputAndValidate(double& WallSpace, double& PaintPrice)
{
double SqreMeters;
double PaintsPrice;
cout << "Enter the square meters: ";
cin >> SqreMeters;
do
{
cout << "Enter the price of paint per liter: ";
cin >> PaintsPrice;
} while (PaintsPrice < MIN_PAINT_COST);
std::cout << std::endl; // <--- Used as a break point for testing.
}
| |
Making a good use of blank lines will allow you to see what you are doing and help to fin what you did wrong.
Like lines 30 - 34. This may be useful for testing what comes after these lines, but you should call the "InputAndValidate(...)" function for this.
For the function:
1 2 3 4
|
void InputAndValidate(double& WallSpace, double& PaintPrice)
{
double SqreMeters;
double PaintsPrice;
| |
As
MikeyBoy said in point 2. Line 1 defines the function with 2 variables passed by reference. Lines 3 and 4 define local variables that
DO NOT affect or change the 2 parameters. So when the function and back in "main" "WallSpace " and "PaintPrice" have not changed. So you are now dealing with 2 variabes that were defined and initialized to (0) zero. Not very useful.
Next you are asking for the "SqreMeters". But is that for 1 wall or 4 walls? Is the person entering the information an employee? If not you may not be getting the correct amount of space. Should you subtract for any doors or windows in the room? Otherwise the painting company could be loosing money having to paint walls not figured into the total price.
Depending on whom is entering the information you can either accept that the number of square meters is correct or ask for the length and height of each wall and figure the total in the function.
The do/while loop is a good start, but read the directions.
● void inputAndValidate function that have two reference parameters,
namely one parameter for the wall space in square meters (thus of type double),
and the other for the price of the paint per liter (also of type double).
This function reads values from keyboard.
The function does not accept a value of less than R20 per liter for the price of the paint,
and it uses a do…while loop to display a message until the user enters a value greater than or equal
to R20 for the price of the paint per liter.
|
Your code:
1 2 3 4 5
|
do
{
cout << "Enter the price of paint per liter :" << endl;
cin >> PaintsPrice;
} while (PaintsPrice<=20);
| |
Indenting is a problem. The minimum price for the paint is "20.0", and should be written that way, but the while condition will not accept a minimum of "20.0". What you want to check for is anything that is less then "20.0". And, according to the instructions, there is no error message to inform the user of an invalid price.
First you need to get this much working before you can continue with the other functions.
Thinking about the program you might consider a struct for most if not all the variables and an array or vector of structs to hold information about each job. Each job may need an array or vector to hold information about each room. It is a thought, but I am not aware of what you have learned or what would be allowed for this program. You will have to enlighten everyone about this.
In the future add some blank lines it helps. The first benefit is to you. I also deleted some extra blank lines that are not needed.
Andy