sigh a little help please

Okay, I'm having a little issue out of my latest program, which yes is a homework assignment. I have the code written, but, for some reason it's not doing like what my professor requires.

This is the output I get from the code..

Number of rooms
3
28 17 20.3
28 17 4.82117-e41

It's supposed to output like this...

3 (For the count)
23 13 18.20 //length, width, and cost per square foot
28 15 20.60
14 11 25.53


Can one of you gurus help me out and tell me what the heck I'm doing wrong? thanks!


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


using namespace std;

void getdata (int&, int&, float&);
float InstalledPrice (int , int, float );
float totalprice (float);
void printdata (int , int, float);



int main()
{

    int length, width, count, i;
    float installation, costpersqfoot, price;

    cout << "Enter the amount of rooms.\n";
    cin >> i;

    for(count = i; count != 0; count --)
    { //beginning of for loop
        getdata (length, width, costpersqfoot);
        installation = InstalledPrice (length, width, costpersqfoot);
        price = totalprice (installation);
        printdata (length, width, price);

    } //end of for loop

}

void getdata(int & length, int & width, float & costpersqft)
{
    cin >> length >> width >> costpersqft;
}

float InstalledPrice (int length, int width, float costpersqfoot)
{
    const float LABOR_COST = 0.35;
    float sqfoot, installation;
    sqfoot = length * width;
    installation = (costpersqfoot * sqfoot) + (LABOR_COST * sqfoot);
}

float totalprice(float installation)
{
    const float TAX_RATE = 0.05;
    float price;
    return(installation * TAX_RATE) + installation;
}

void printdata(int length, int width, float price)
{
    cout << length << " " << width << " " << price << endl;
}
Last edited on
After line 44, you should return a value.
return a value as in return 0; or return as in what I have on line 51? I know it's something simple but for some reason I can't figure it out. Been working on this code for about 6 hrs now. ><
I think you mean to return the value you've calculated at line 44? The value that you then mean to send to the totalprice function at line 27.
Okay, lets try to add that and see what we come up with. I'll try to add the return to that function call.
I believe that, that may have been my issue. I knew it was something easy and my dumbass was overlooking it the whole time.
Looks to me like you could either

return installation; after line 44,

or

return (costpersqfoot * sqfoot) +(. . . etc. ); as line 44.

In the second case you don't need to declare or calculate installation since it's what you're returning.
Now I have to get my math right because it's def not adding up to the right price.
What exactly are you inputting into your program?

@jib nevermind I'm a dumbass it's adding everything correctly. I forgot I was adding the square footage of 3 rooms instead of 1 room.
thanks to all for the push in the right direction.
Topic archived. No new replies allowed.