NEED HELP!!!

Hi,

I'm attempting to write this program for an assignment in my c++ class.
I have the base of the program finished, but I can't get the results to fill in the correct places. I know I have something written wrong in the code, but I've tried a lot of different things and I haven't been able to find the source of the issue....



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
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

//Necessary information:
// - 115ft of wall = 8 hours of labor = 1 gallon of paint
// - $18 per 1 hour of labor

//Painting Program
void displayInstructions();

float computePaint(int area, float gallon);

float computeLabor(int area);

float computeTotal(float paint, float labor);

void outputResults(int area, float paint, float labor, float total);

int main()
{

  displayInstructions();

  return 0;

}


void displayInstructions()
{
  int area;
  float gallon, total, paint, labor;

  //Starting program
  cout << "****************************************************" << endl;
  cout << "Welcome to the paint calculator" << endl;
  cout << "Input: square feet, cost of paint per gallon" << endl;
  cout << "Output: paint cost, labor cost ($18 per hour), total cost" << endl;
  cout << "****************************************************" << endl;
  cout << endl;
  //Start asking for variables
  cout << "How many square feet of wall space is to be covered? " << endl;
  cin >> area;
  cout << endl;
  cout << "What is the cost of the paint per gallon? " << endl;
  cin >> gallon;

  paint = computePaint(area, gallon);
  labor = computeLabor(area);
  total = computeTotal(paint, labor);
  outputResults(area, paint, labor, total);


}

float computePaint(int area, float gallon)
{
  float paint = (area/115) * gallon;
  return paint;
}

float computeLabor(int area)
{
  float labor = ((area/115) * 8) * 18;
  return labor;
}

float computeTotal(float paint, float labor)
{
  float total = paint + labor;
  return total;
}

void outputResults(int area, float total, float paint, float labor)
{
  cout << setprecision(2) << fixed << endl;
  cout << left;
  cout << setw(15) << "Square Feet:" << area << endl;
  cout << setw(15) << "Paint Cost:" << "$" << paint << endl;
  cout << setw(15) << "Labor Cost:" << "$" << labor << endl;
  cout << setw(15) << "Total Cost;" << "$" << total << endl;
  cout << endl;

}
What input did you test with? What was the expected output? What was the actual output?

Anyway one problem I saw in computePaint(int area, float gallon) is
 
float paint = (area/115) * gallon;


An integer divided by an integer will always give an integer as result.
Let's say area is 200 and gallon = 15 would give 200 / 115 = 1 * 15 = 15
correct would be 1.7 * 15 = 26.
To solve the problem you need to use a float for area.
Same in computeLabor()
Actual Output:
****************************************************
Welcome to the paint calculator
Input: square feet, cost of paint per gallon
Output: paint cost, labor cost ($18 per hour), total cost
****************************************************

How many square feet of wall space is to be covered?
12900

What is the cost of the paint per gallon?
12.00

Square Feet: 12900.00
Paint Cost: $16153.04
Labor Cost: $17499.13
Total Cost; $1346.09



Expected Output:
****************************************************
Welcome to the paint calculator
Input: square feet, cost of paint per gallon
Output: paint cost, labor cost ($18 per hour), total cost
****************************************************

How many square feet of wall space is to be covered?
12900

What is the cost of the paint per gallon?
12.00

Square Feet: 12900
Paint Cost: $1346.09
Labor Cost: $16153.04
Total Cost: $17499.13



I changed the areas to float instead of integer but still getting a mixup

closed account (E0p9LyTq)
Look at the variable ordering on your outputResults function prototype:

void outputResults(int area, float paint, float labor, float total);

Now look at the variable ordering in the function definition:

void outputResults(int area, float total, float paint, float labor)

You are getting the correct output, you are merely sending the wrong data to the variables. Here's your function call:

outputResults(area, paint, labor, total);

Ooops! Change the function definition to match your prototype declaration and you will get the proper output.
I think you got the parameters wrong.

in main () you call
1
2
outputResults(area, paint, labor, total);
void outputResults(float area, float total, float paint, float labor)


Topic archived. No new replies allowed.