thi is my online exam i need some help! don't know how to start

Jun 9, 2020 at 10:16am
Write a program that outputs inflation rates for two successive years
and whether the inflation is increasing or decreasing. Ask the user to
input the current price of an item and its price one year and two years
ago. To calculate the inflation rate for a year, subtract the price of the
item for that year from the price of the item one year ago and then
divide the result by the price a year ago. Your program must contain at
least the following functions: a function to get the input, a function to
calculate the results, and a function to output the results. Use appro-
priate parameters to pass the information in and out of the function.
Do not use any global variables.
Last edited on Jun 30, 2020 at 11:48am
Jun 9, 2020 at 10:51am
nockson wrote:
Write a program that prompts the user to input two positive integers. The program should have a void function named multiple that has four parameters (two value parameters and two reference parameters). This function received two positive integers from the function main. After the multiple function performs several calculations, the function main should output how many numbers


Break it down into tasks. The first task is:

Write a program that prompts the user to input two positive integers.


Do you know how to do that?
Last edited on Jun 9, 2020 at 10:51am
Jun 9, 2020 at 12:26pm
yes I know the syntax
Jun 9, 2020 at 12:28pm
I found the solution thanks
Jun 9, 2020 at 12:33pm
Please DON'T go editing your posts to change the question after you've had replies. It makes the thread impossible to understand for anyone else.

Luckily, I'd quoted the original question, so it can still be seen. For the record, in case the OP does it again, here's the second question:

nockson wrote:
A painting company has determined that for every 8 square meters of wall space, one litre of paint and 1.5 hours of labour will be required. The company charges R55 per hour of labour. You have been tasked to write a program that allows the user to enter the square metres 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 litres of paint required  The hours of labour required  The cost of the paint  The labour 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 metres (thus of type double), and the other for the price of the paint per litre (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 litre.  void determineLabourAndPaint with three parameters: one value parameter to supply the wall space; and two reference parameters for the hours of labour and litres 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 labour, litres of paint required and the price of the paint per litre; and two reference parameters for the cost of the labour and the cost of the paint. Remember that the company charges R55 per hour of labour.


Just for the record - your teacher is OK with you going online to get help with an exam, yes?
Last edited on Jun 9, 2020 at 12:37pm
Jun 9, 2020 at 2:50pm
yes there is no problem
Jun 9, 2020 at 4:37pm
So, again, break it down into tasks (the first of which is almost identical to the previous question). Do each task in turn. Each new bit you write, make sure it compiles, and test that it works, before moving on to the next bit.

Y'know, the stuff you should already be doing with each and every single program you write, yes?
Jun 9, 2020 at 7:47pm
yes I know the staff but structuring the code the that the challenge actually
Jun 9, 2020 at 10:08pm
Here's a starting point that shows how you can structure the code. This code compiles as is. Take it, compile it for yourself. As you make small changes, keep compiling along the way. If you get to a point where it doesn't build, STOP and fix your mistake.
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <iostream>

/*
void inputAndValidate function that have two reference parameters, namely one parameter
for the wall space in square metres (thus of type double), and the other for the price of
the paint per litre (also of type double).
*/
void inputAndValidate(double& wallSpace, double& priceOfPaintPerLiter);

/*
void determineLabourAndPaint with three parameters: one value parameter to supply the wall space
and two reference parameters for the hours of labour and litres of paint required which should
be returned to the main function.
*/
void determineLaborAndPaint(double wallSpace, double& laborHours, double& litersOfPaint);

/*
void determineCost with five parameters:
   three value parameters to supply the hours of labour,
                                    litres of paint required
                                    and the price of the paint per litre;
   and two reference parameters for the cost of the labour
                                and the cost of the paint.
*/
void determineCost(double laborHours,
                   double litersOfPaint,
                   double priceOfPaintPerLiter,
                   double& costOfLabor,
                   double& costOfPaint);

int main()
{
    // use inputAndValidate function to get the wall space to paint and
    // the price per liter of paint

    // use determineLaborAndPaint function to get the labor hours and paint amount it will
    // take to cover the space obtained from the previous step

    // use determineCost to determine how much the paint and labor will cost
    // based on info gathered in the previous two steps

    /*
    The program should display the following data for each job:
        The number of liters of paint required
        The hours of labour required
        The cost of the paint
        The labour charges
        The total cost of the paint job.
    */

    return 0;
}

void inputAndValidate(double& wallSpace, double& priceOfPaintPerLiter)
{
    /*
    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 litre.
    */
    const double MIN_PAINT_COST = 20.0;

    // get the amount of wallspace from the user

    // get an appropriate price-per-liter from the user
}

void determineLaborAndPaint(double wallSpace, double& laborHours, double& litersOfPaint)
{
    /*
    A painting company has determined that for every 8 square meters of wall space,
    one litre of paint and 1.5 hours of labour will be required.
    */
    const double LITERS_PER_METERS_SQ = (1.0 / 8.0);
    const double LABOR_HRS_PER_METERS_SQ = (1.5 / 8.0);

    // determine number of labor hours for the given wallspace
    // determine the amount of paint to use given the wallspace
}

void determineCost(double laborHours,
    double litersOfPaint,
    double priceOfPaintPerLiter,
    double& costOfLabor,
    double& costOfPaint)
{
    // The company charges R55 per hour of labour
    const double LABOR_COST_PER_HOUR = 55.0;

    // calculate cost of labor
    // calculate cost of paint
}
Jun 10, 2020 at 6:28am
here is an example of what I put, but it doesn't do all the calculation.
#include<iostream>
#include<iomanip>
using namespace std;
const double NR_JOBS = 6;
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 Numspaintliters=0.0;
double Wallspace=0.0;
double SqreMeters=0.0;
double PaintsPrice=0.0;

cout << fixed << showpoint << setprecision(2);
cout << "Enter the square meters : " << endl;
cin >> Wallspace;
cout << "Enter the price per liter :" << endl;
cin >> PaintsPrice;
determineLabourAndpaint(Wallspace, hourslabour, Numspaintliters);


int i = 1;

for (i = 1; i <= NR_JOBS; i++)
{




determineCost(hourslabour, Numspaintliters, PaintsPrice, LabourCharges, CostPaint);





}

return 0;
}

void InputAndValidate(double& WallSpace, double& PaintPrice)
{
double SqreMeters;
double PaintsPrice;
cout << "Enter the square meters :" << endl;
cin >> SqreMeters;
do
{
cout << "Enter the price of paint per liter :" << endl;
cin >> PaintsPrice;

} while (PaintsPrice<=20);

}

void determineLabourAndpaint(double WallSpace, double& hourslabour, double& paintrequired)
{

double Numspaintliters=0.0;
double Hourslabour=0.0;
double Wallsapce=0.0;
while (Wallsapce == 8)
{
Numspaintliters = Wallsapce / 8;

Hourslabour = Wallsapce / 8 * 1.5;

cout << "The number of liters of paint require is :" << Numspaintliters << endl;
cout << "The hours of labour required is :" << Hourslabour << endl;

}

}

void determineCost(double hourslabour, double NumsPaintLiters, double Pricepaint, double& LabourCost, double& Costpaint)
{
const double labourCost = 55;
double Numpaintliters=0.0, Hourslabour=0.0;
double CostPaint;
double TotalCost;

CostPaint = Numpaintliters + Hourslabour;
TotalCost = CostPaint + labourCost;

cout << "The total cost for the paint job is:" << TotalCost << endl;
cout << "The cost of the paint is :" << CostPaint << endl;


}



Jun 10, 2020 at 10:43am
1) Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) Your determineLabourAndpaint() function takes an argument called WallSpace, and completely ignores it. Instead, you use a local variable called Wallsapce, which you initialise to 0.0 and never change, which means that the while loop never iterates even once.
Last edited on Jun 10, 2020 at 10:43am
Jun 10, 2020 at 3:57pm
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
Topic archived. No new replies allowed.