Code compiles but input and output is incorrect

So my code is compiling but not inputting or outputting the way that I am looking for. My

As always any and all help is very appreciated thanks so much.

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
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

void getdata (int& length , int& width, float& costperdqfoot);
float InstalledPrice (int length, int width, float costpersquarefoot);
float totalprice (float installation);
void printdata (int length, int width, float price, float installation, float total);
const float LABOR_COST=0.35;
const float TAX_RATE=0.05;

int main()
{ 
    int length, width;
    float installation, total, costpersqfoot, price;
    
    int num;
    cout<< "Enter the amount of the count:"<<endl;
    cin>>num;
    const int MAXCOUNT = num;
    int count;
    
    for (count = 0; count < MAXCOUNT; count++)
    { 
      getdata (length, width, costpersqfoot);
      installation = InstalledPrice (length, width, costpersqfoot);
      total = totalprice (installation);
      printdata (length, width, price, 0, 0);
    } 
    system("pause");
    return 0;
}
void getdata (int& length, int& width, float& costpersqfoot)
{
 cout<< "Enter the length, width, and cost per square foot"<<endl;
 cin>> length >> width >> costpersqfoot;
}    
float InstalledPrice (int length, int width, float costpersqfoot)
{
 return (length*width*costpersqfoot)+(length*width*LABOR_COST);
}
float totalprice (float installation)
{
 return (installation*TAX_RATE);
}

void printdata (int length, int width, float price, float installation, float total)
{
 cout<< "The cost for installation is: "<< installation<< endl;
 cout<< "The total cost with tax is: "<< total<< endl;
}
Last edited on
The first thing I did was take out "price" you had declared it but never used it.

Second was change printdata (length, width, price, 0, 0); to

printdata (length, width, installation, total);

Third was to make installation and total reference variables in the printdata functions.

Here is the code that has my changes made

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
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

void getdata (int& length , int& width, float& costperdqfoot);
float InstalledPrice (int length, int width, float costpersquarefoot);
float totalprice (float installation);
void printdata (int length, int width,  float& installation, float& total);
const float LABOR_COST=0.35;
const float TAX_RATE=0.05;

int main()
{ 
    int length, width;
    float installation, total, costpersqfoot, price;
    
    int num;
    cout<< "Enter the amount of the count:"<<endl;
    cin>>num;
    const int MAXCOUNT = num;
    int count;
    
    for (count = 0; count < MAXCOUNT; count++)
    { 
      getdata (length, width, costpersqfoot);
      installation = InstalledPrice (length, width, costpersqfoot);
      total = totalprice (installation);
	  printdata (length, width, installation, total);
    } 
    system("pause");
    return 0;
}
void getdata (int& length, int& width, float& costpersqfoot)
{
 cout<< "Enter the length, width, and cost per square foot"<<endl;
 cin>> length >> width >> costpersqfoot;
}    
float InstalledPrice (int length, int width, float costpersqfoot)
{
 return (length*width*costpersqfoot)+(length*width*LABOR_COST);
}
float totalprice (float installation)
{
 return (installation*TAX_RATE);
}

void printdata (int length, int width,  float& installation, float& total)
{
 cout<< "The cost for installation is: "<< installation<< endl;
 cout<< "The total cost with tax is: "<< total<< endl;
}
This is helpful for sure thank you I figured out some other problems in the code as well. Thanks for your help again.
Last edited on
Topic archived. No new replies allowed.