Am I using structures properly? Find my error

I am doing a homework assignment where I have to make a structure. I followed the directions word for word, but am not getting the correct output. There must be a logic error somewhere as there are no syntax errors. I just can't find the logic error.

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
180
181
182
183
184
185
186
187
188
189
#include<iostream>
#include<iomanip>
#include<string>
#include<cctype>
using namespace std;

const string CARPOOL = "Carpool",
             FAMILY = "Family",
             SPORT = "Sport";

// TODO (Objective 1):	Replace named constants for capacity groupings with
//						the required CapacityGroup enumeration

enum CapacityGroup{CG_ERR, CG_1_2, CG_3_4, CG_5_6, CG_7_8, CG_9_12};

// Named constants for seating capacity groupings

// TODO (Objective 2):	Define the required Vehicle structure with two fields
struct Vehicle
{
	string category;
	int occupants;
};

//          category:       type string
//          occupants:      type int



//------------------------------------------------------------------------------

// function prototype declarations
void DisplayResults(string category, int occupants);

// TODO (Objective 3a): Replace string and int paramters with 1 Vehicle structure type
string GetRecommendation(Vehicle motorVehicle);


// OPTIONAL (Idea 1a): Change return type to CapacityGroup
int GetCapacityGroup(int occupants);


// OPTIONAL (Idea 2a): Change parameter type to CapacityGroup
string GetCarpoolRecommendation(int group);
string GetFamilyRecommendation(int group);
string GetSportRecommendation(int group);


//------------------------------------------------------------------------------

int main()
{
    /*
        DO NOT MODIFY the main() function block!
    */

    cout << endl
         << "------------------------------------------------------" << endl
         << "This program recommends a vehicle based on its purpose" << endl
         << "and the seating capacity for expected occupants." << endl
         << "------------------------------------------------------" << endl
         << endl;

    // Test Carpool category.

    cout << CARPOOL << ":" << endl;

    for(int occupants = 13; occupants >= 0; occupants--)
        DisplayResults(CARPOOL, occupants);

    cout << endl;

      // Test Family category.

    cout << FAMILY << ":" << endl;

    for(int occupants = 13; occupants >= 0; occupants--)
        DisplayResults(FAMILY, occupants);

    cout << endl;

      // Test Sport category.

    cout << SPORT << ":" << endl;

    for(int occupants = 13; occupants >= 0; occupants--)
        DisplayResults(SPORT, occupants);

    cout << endl;

      // Test unknown and not specified category

    cout << "Other:" << endl;

    DisplayResults("Vacation", 5);          // category unknown
    DisplayResults("", -1);                 // category not specified

    cout << endl << "- End Program - " << endl;
}

//------------------------------------------------------------------------------


void DisplayResults(string category, int occupants)
{
    // TODO (Objective 3c): Declare Vehicle structure variable
	Vehicle motorVehicle;

    // TODO (Objective 3c): Initialize Vehicle fields with function parameter values
	category = motorVehicle.category;
	occupants = motorVehicle.occupants;

    // TODO (Objective 3c): Replace function call arguments with 1 Vehicle structure variable
    string recommendation = GetRecommendation(motorVehicle);



    cout << setw(12) << occupants << " occupants - "
         << recommendation << endl;
}

//------------------------------------------------------------------------------

// OPTIONAL (Idea 1a): Change return type to CapacityGroup
int GetCapacityGroup(int occupants)
{
    // OPTIONAL (Idea 1b): Change variable type to match function return type
    int group;


    if( occupants < 1 || occupants > 12 )   // invalid
        group = CG_ERR;
    else if( occupants >= 9 )               // 9-12
        group = CG_9_12;
    else if( occupants >= 7 )               // 7-8
        group = CG_7_8;
    else if( occupants >= 5 )               // 5-6
        group = CG_5_6;
    else if( occupants >= 3 )               // 3-4
        group = CG_3_4;
    else                                    // 1-2
        group = CG_1_2;

    return group;
}

//------------------------------------------------------------------------------

// TODO (Objective 3a): Replace string and int parameters with 1 Vehicle parameter
string GetRecommendation(Vehicle motorVehicle)
{
    // TODO (Objective 3b): Use Vehicle fields where necessary in place of
    //						string and int parameters.
    // NOTE:				Should require 4 modifications


    // OPTIONAL (Ideas 1c/2b): Change variable type to match function return type
    // Get the capacity group for the occupants parameter.

    int group = GetCapacityGroup(motorVehicle.occupants);




    string recommendation;

    // Compare the category parameter to string constants.

    if( motorVehicle.category == CARPOOL )
    {
      recommendation = GetCarpoolRecommendation(group);
    }
    else if( motorVehicle.category == FAMILY )
    {
      recommendation = GetFamilyRecommendation(group);
    }
    else if( motorVehicle.category == SPORT )
    {
      recommendation = GetSportRecommendation(group);
    }
    else
    {
      recommendation = "Purpose unknown or not specified.";
    }

    return recommendation;
}

//------------------------------------------------------------------------------ 
Last edited on

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
 // OPTIONAL (Idea 2a): Change parameter type to CapacityGroup
string GetCarpoolRecommendation(int group)
{
    string recommendation;

    switch( group )
    {
      case CG_9_12:  recommendation = "Dodge Sprinter Wagon";
                     break;
      case CG_7_8:   recommendation = "Ford E-150 XL";
                     break;
      case CG_5_6:   recommendation = "Chrysler Town and Country";
                     break;

      case CG_3_4:
      case CG_1_2:   recommendation = "Consider a smaller vehicle.";
                     break;

      default: recommendation = "No recommendation for this capacity.";
    }

    return recommendation;
}

//------------------------------------------------------------------------------

// OPTIONAL (Idea 2a): Change parameter type to CapacityGroup
string GetFamilyRecommendation(int group)
{
    string recommendation;

    switch( group )
    {
      case CG_9_12:  recommendation = "Consider a larger vehicle.";
                     break;

      case CG_7_8:   recommendation = "Honda Odyssey";
                     break;
      case CG_5_6:   recommendation = "Buick Lucerne";
                     break;
      case CG_3_4:   recommendation = "Chevy Malibu";
                     break;

      case CG_1_2:   recommendation = "Consider a smaller vehicle.";
                     break;

      default: recommendation = "No recommendation for this capacity.";
    }

    return recommendation;
}

//------------------------------------------------------------------------------


// OPTIONAL (Idea 2a): Change parameter type to CapacityGroup
string GetSportRecommendation(int group)
{
    string recommendation;

    switch( group )
    {
      case CG_9_12:
      case CG_7_8:
      case CG_5_6:   recommendation = "Consider a larger vehicle.";
                     break;

      case CG_3_4:   recommendation = "Ford Mustang";
                     break;
      case CG_1_2:   recommendation = "Dodge Viper";
                     break;

      default: recommendation = "No recommendation for this capacity.";
    }

    return recommendation;
}



------------------------------------------------------
This program recommends a vehicle based on its purpose
and the seating capacity for expected occupants.
------------------------------------------------------

Carpool:
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.

Family:
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.

Sport:
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.

Other:
  -858993460 occupants - Purpose unknown or not specified.
  -858993460 occupants - Purpose unknown or not specified.

- End Program -
Press any key to continue . . .
Last edited on
1
2
3
   // TODO (Objective 3c): Initialize Vehicle fields with function parameter values
	category = motorVehicle.category;
	occupants = motorVehicle.occupants;


You're supposed to initialize the vehicle fields from the parameter values. Not set the parameter values to the uninitialized vehicle fields.
Yup, I fixed that but now the output is...


------------------------------------------------------
This program recommends a vehicle based on its purpose
and the seating capacity for expected occupants.
------------------------------------------------------

Carpool:
          13 occupants - Purpose unknown or not specified.
          12 occupants - Purpose unknown or not specified.
          11 occupants - Purpose unknown or not specified.
          10 occupants - Purpose unknown or not specified.
           9 occupants - Purpose unknown or not specified.
           8 occupants - Purpose unknown or not specified.
           7 occupants - Purpose unknown or not specified.
           6 occupants - Purpose unknown or not specified.
           5 occupants - Purpose unknown or not specified.
           4 occupants - Purpose unknown or not specified.
           3 occupants - Purpose unknown or not specified.
           2 occupants - Purpose unknown or not specified.
           1 occupants - Purpose unknown or not specified.
           0 occupants - Purpose unknown or not specified.

Family:
          13 occupants - Purpose unknown or not specified.
          12 occupants - Purpose unknown or not specified.
          11 occupants - Purpose unknown or not specified.
          10 occupants - Purpose unknown or not specified.
           9 occupants - Purpose unknown or not specified.
           8 occupants - Purpose unknown or not specified.
           7 occupants - Purpose unknown or not specified.
           6 occupants - Purpose unknown or not specified.
           5 occupants - Purpose unknown or not specified.
           4 occupants - Purpose unknown or not specified.
           3 occupants - Purpose unknown or not specified.
           2 occupants - Purpose unknown or not specified.
           1 occupants - Purpose unknown or not specified.
           0 occupants - Purpose unknown or not specified.

Sport:
          13 occupants - Purpose unknown or not specified.
          12 occupants - Purpose unknown or not specified.
          11 occupants - Purpose unknown or not specified.
          10 occupants - Purpose unknown or not specified.
           9 occupants - Purpose unknown or not specified.
           8 occupants - Purpose unknown or not specified.
           7 occupants - Purpose unknown or not specified.
           6 occupants - Purpose unknown or not specified.
           5 occupants - Purpose unknown or not specified.
           4 occupants - Purpose unknown or not specified.
           3 occupants - Purpose unknown or not specified.
           2 occupants - Purpose unknown or not specified.
           1 occupants - Purpose unknown or not specified.
           0 occupants - Purpose unknown or not specified.

Other:
           5 occupants - Purpose unknown or not specified.
          -1 occupants - Purpose unknown or not specified.

- End Program -
Press any key to continue . . .



Something is wrong with GetRecommendation
Last edited on
I changed those lines to this:

1
2
3
// TODO (Objective 3c): Initialize Vehicle fields with function parameter values
	motorVehicle.category;
	motorVehicle.occupants;


Hopefully that is correct.
Last edited on
Ahhhh solved. Had it flip-flopped;

1
2
3
// TODO (Objective 3c): Initialize Vehicle fields with function parameter values
	motorVehicle.category = category;
	motorVehicle.occupants = occupants;
Topic archived. No new replies allowed.