Help please! (Strings)

When I run my program, why is it not displaying what my color is at the end?

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
167
168
169
170
171
172
173
174
175
176
177
178
179
#include <iostream>
#include <string>

using namespace std;

enum FP_COLOR {RED, ORANGE, YELLOW, GREEN, BLUE, VIOLET};
//enum FP_SHAPE {Square, Round, Triangular};

const int maxStringSize = 100;
const char FP_COLOR_ARRAY[6][maxStringSize] = 
{{"red"}, {"orange"}, {"yellow"}, {"green"}, {"blue"}, {"violet"}};


class FlowerPot
{
 public:

    //CONSTRUCTORS
      FlowerPot(int depth, int height, int width);

    //ACCESSORS
      void SetColor(string color);
      
      void SetHeight(int height) ;
      void SetWidth(int width) ;
      void SetDepth(int depth) ;

      string GetColor();

      int GetHeight() ;
      int GetWidth() ;
      int GetDepth() ;
      int GetVolume() ;

    //OTHER METHODS

private:
    //VARIABLES    
      string FPcolor;

      int FPheight;
      int FPwidth;
      int FPdepth;
};

    //FLOWERPOT METHODS

      FlowerPot::FlowerPot(int depth, int height, int width)
      {
       FPdepth = depth;       
       FPheight = height;
       FPwidth = width;
      }


      void FlowerPot::SetColor(string color) { FPcolor = color;}

      void FlowerPot::SetHeight(int height)      
      { 
        FPheight = height; 
      }
      void FlowerPot::SetWidth(int width)        
      { 
        FPwidth = width; 
      }
      void FlowerPot::SetDepth(int depth)        
      {
        FPdepth = depth; 
      }

      string FlowerPot::GetColor()           { return FPcolor; }

      int FlowerPot::GetHeight()                 { return FPheight; }
      int FlowerPot::GetWidth()                  { return FPwidth; }
      int FlowerPot::GetDepth()                  { return FPdepth; }
      int FlowerPot::GetVolume()                 { return FPheight*FPwidth*FPdepth; }




//MAIN
int main()
{

 //CREATE FLOWERPOTS
   int NumOfFlowerPots;
   cout << "How many flower pots would you like to create? ";
   cin >> NumOfFlowerPots;

   FlowerPot* flowerPotArray[5];

    for (int i = 0; i<NumOfFlowerPots; i++)
    {
       int width;
       int depth;
       int height;
       string color;

       cout << endl << "Flower pot " << i+1 << ":";
      //width
       cout << endl << "How wide is the flower pot? ";
       cin >> width;
      //depth
       cout << endl << "How deep is the flower pot? ";
       cin >> depth;
      //height
       cout << endl << "How tall is the flower pot? ";
       cin >> height;
      //color
       bool recognized = false;
       while (recognized == false)
       {
          string userstring("000");
          cout << endl << "What color? " << endl;
          cout << "Choices are: red, orange, yellow, green, blue, violet." << endl;

          cin >> userstring;


          if (userstring.compare(FP_COLOR_ARRAY[RED]) == 0)
          {
          color = "red";
          recognized = true;
          }

          if (userstring.compare(FP_COLOR_ARRAY[ORANGE]) == 0)
          {
          color = "orange";
          recognized = true;
          }

          if (userstring.compare(FP_COLOR_ARRAY[YELLOW]) == 0)
          {
          color = "yellow";
          recognized = true;
          }

          if (userstring.compare(FP_COLOR_ARRAY[GREEN]) == 0)
          {
          color = "green";
          recognized = true;
          }

          if (userstring.compare(FP_COLOR_ARRAY[BLUE]) == 0)
          {
          color = "blue";
          recognized = true;
          }

          if (userstring.compare(FP_COLOR_ARRAY[VIOLET]) == 0)
          {
          color = "violet";
          recognized = true;
          }

          if (recognized == false)
          {
          cout << "Sorry, your entry did not match a color." << endl << "Please try again.";
          }
       }//end of while loop
      //
       FlowerPot* FP = new FlowerPot(depth, height, width);
       flowerPotArray[i] = FP; 
    }

  //DISPLAY FLOWERPOTS
    cout << endl;

    for (int i = 0; i<NumOfFlowerPots; i++)
    {
     cout << "Volume of flower pot " << i+1 << ": " << flowerPotArray[i]->GetVolume() << endl;
     cout << "Color of flower pot " << i+1 << ": " << flowerPotArray[i]->GetColor() << endl;
    }


cout << endl;
system ("pause");
return(0);
}
Notice how when you run it, the line "Color of flower pot x:" is empty.
You forgot to set the color after creating the FlowerPot.

FP->SetColor(color);
Last edited on
Ahahahah oh my gosh! I was ripping my hair out last night. Thanks.
Topic archived. No new replies allowed.