how to display inputed values

Program works perfectly fine. I input in the length, width and height. But i want it to display those values for every individual prism when i output... along with the area and volume which i already have. Since i made a vector i won't let me cout it normally.


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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include <iostream>
#include <vector>

using namespace std;




class Rectangle{

public:

Rectangle();



void setLength(double length){


l=length;

}


void setWidth(double width){


w=width;

}


void setHeight(double height){



h=height;


}


double getArea(double sa);//Surface Area
double getVolume(double v);

void dispaly();


private:

double l;
double w;
double h;


double sa, v;

};

vector<Rectangle>ord;


Rectangle::Rectangle()
{

l=0;
w=0;
h=0;



}




double Rectangle::getArea(double sa){

sa=2*(w*h+l*w+l*h);

return sa;
}

double Rectangle::getVolume(double v){

v=l*w*h;

return v;
}


int main(){

double length, width, height;
double sa, v;
int count=0;

int h;


Rectangle p;



do{


cout<<"Enter you length: ";
cin>>length;
p.setLength(length);



cout<<"Enter your width: ";
cin>>width;
p.setWidth(width);

cout<<"Enter your height: ";
cin>>height;
p.setHeight(height);

cout<<"\n";


ord.push_back(p);

count++;


}while (count<5);


 for(int i = 0; i < count; i++){

			  for (int m = count-1; m > 0; m--)
  {
         for (int n = 0; n < m; n++)
         {
             if (ord[n].getVolume(v) > ord[n+1].getVolume(v))
             {
                Rectangle temp = ord[n];
                ord[n] = ord[n+1];
                ord[n+1] = temp;
                }
             }



  }



cout<<"SA: "<<ord[i].getArea(sa)<<endl;

cout<<"V: "<<ord[i].getVolume(v)<<endl;



cout<<"\n";


}



}
Last edited on
nvm fixed it just changed private variables and made them public
Last edited on
double sa, v; at line 95 are being used without having been initialized. Meaning there is garbage value stored in these two variables.
At line 98: No use of h.
Topic archived. No new replies allowed.