Sorting By Mileage

My next part to the code is doing a selection sort and displaying my array in that sort! Can someone please tell me if it looks like I am doing this right or do I need to change something up?

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
#include "CarClass.h"
using namespace std;

//Set up Search 
int search(Car object[], int size, int value)
{
   int index = 0;         // Used as a subscript to search array 
   int position = -1;     // Used to record position of search value 
   bool found = false;    // Flag to indicate if the value was found 

   while (index < size && !found)
   {
      if (object[index].getVIN() == value) // If the value is found
      {
         found = true;          // Set the flag 
         position = index;      // Record the value's subscript 
      }
      index++;                  // Go to the next element 
   }
   return position;             // Return the position
}// End search 

//Sort Array
void selectionSort(int array[], int size)
{
	int startScan, minIndex, minValue;

	for (startScan = 0; startScan < (size - 1); startScan++)
	{
		minIndex = startScan;
		minValue = array[startScan];
		for(int index = startScan + 1; index < size; index++)
		{
			if (array[index] < minValue)
			{
				minValue = array[index];
				minIndex = index;
			}
      }
		array[minIndex] = array[startScan];
		array[startScan] = minValue;
	}
}


int search(Car[], int, int);
void selectionSort(Car[], int, int);
void showArray(Car[], int, int);

int main() {
        
	const int SIZE = 9;
			
	//Array of 9 cars
	Car Car_array[SIZE] = { Car("Porsche", "911", "Silver", 2005, 18990, 1237362727), 
							Car("Ford", "Mustang", "Red", 2007, 49842, 7337372239),
							Car("Chevrolet", "Beretta", "Black", 1989, 90332, 2873644922),
							Car("Ford", "Focus", "White", 2008, 150, 9236498273),
							Car("Voltzwagon", "Jetta", "Black", 2006, 28002, 4673992056),
							Car("Rolls Royce", "Ghost", "Silver", 2005, 10000, 9292983855),
							Car("Mazda", "626", "Blue", 2002, 84754, 7364646463),
							Car("Toyota", "Camry", "Red", 2004, 50332, 2133737227),
							Car("Bugatti", "Veyron 16.4", "White", 2010, 5, 5712893401)};

	
	long long int manualVIN= 2873644922;
	long long int desiredVIN;
	int posLin; // Used to search for VIN 2873644922
	int pos;  // Used for when user wil input the vin they want to search

	//MANUAL LINEAR SEARCH FOR VIN NUMBER
	
		posLin = search(Car_array, SIZE, manualVIN); 

		if (posLin == -1)
			cout << "You do not have a car with the VIN Number 2873644922.\n";
		else 
		{
			cout << "You do have a car on the lot with the VIN Number 2873644922.\n";
		}
		cout << "_______________________________________________________\n";
	// END MANUAL LINEAR SEARCH FOR VIN NUMBER

	// Get the VIN to search for

	 // LINEAR SEARCH FOR VIN NUMBER
		cout << "Enter a VIN number to search for: ";
		cin >> desiredVIN;

	// Linear Search for VIN Number
		pos = search(Car_array, SIZE, desiredVIN); 

		if (pos == -1)
			cout << "You do not have a car with the VIN Number " << desiredVIN << ".\n";
		else 
		{
			cout << "You do have a car on the lot with the VIN Number " << desiredVIN << ".\n";
		}
		cout << "_______________________________________________________\n";

	 // END LINEAR SEARCH FOR VIN NUMBER
	
	// Loop to display car details
		for (int x=0; x<9; x++) {
			Car_array[x].car_details();
		}

		cout << "_______________________________________________________\n";


		//Selection Sort

		cout << " This is the Array of Cars in a selection sort!!\n\n";

		//Sort the Array
		selectionSort(Car_array, SIZE, Car::getMileage);

		//Display 
		showArray();
		
		//Show Array

		void showArray();
		{
			for (int x=0; x<9; x++) {
					Car_array[x].car_details();
				}
		}
		return 0;

}


Oh and I am sorting based on mileage!
Can someone please tell me what I am doing wrong...this will not sort by mileage and then print it

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

#include "CarClass.h"
using namespace std;

//Set up Search 
int search(Car object[], int size, int value)
{
   int index = 0;         // Used as a subscript to search array 
   int position = -1;     // Used to record position of search value 
   bool found = false;    // Flag to indicate if the value was found 

   while (index < size && !found)
   {
      if (object[index].getVIN() == value) // If the value is found
      {
         found = true;          // Set the flag 
         position = index;      // Record the value's subscript 
      }
      index++;                  // Go to the next element 
   }
   return position;             // Return the position
}// End search 

//Sort Array
void selectionSort(Car object[], int size, int value)
{
	int startScan, minIndex, minValue;

	for (startScan = 0; startScan < (size - 1); startScan++)
	{
		minIndex = startScan;
		minValue = array[startScan];
		for(int index = startScan + 1; index < size; index++)
		{
			if (array[index] < minValue)
			{
				minValue = array[index];
				minIndex = index;
			}
      }
		array[minIndex] = array[startScan];
		array[startScan] = minValue;
	}
}


int search(Car[], int, int);
void selectionSort(Car[], int, int);
void showArray();
int main() {
        
	const int SIZE = 9;
			
	//Array of 9 cars
	Car Car_array[SIZE] = { Car("Porsche", "911", "Silver", 2005, 18990, 1237362727), 
							Car("Ford", "Mustang", "Red", 2007, 49842, 7337372239),
							Car("Chevrolet", "Beretta", "Black", 1989, 90332, 2873644922),
							Car("Ford", "Focus", "White", 2008, 150, 9236498273),
							Car("Voltzwagon", "Jetta", "Black", 2006, 28002, 4673992056),
							Car("Rolls Royce", "Ghost", "Silver", 2005, 10000, 9292983855),
							Car("Mazda", "626", "Blue", 2002, 84754, 7364646463),
							Car("Toyota", "Camry", "Red", 2004, 50332, 2133737227),
							Car("Bugatti", "Veyron 16.4", "White", 2010, 5, 5712893401)};

	
	long long int manualVIN= 2873644922;
	long long int desiredVIN;
	int posLin; // Used to search for VIN 2873644922
	int pos;  // Used for when user wil input the vin they want to search

	//MANUAL LINEAR SEARCH FOR VIN NUMBER
	
		posLin = search(Car_array, SIZE, manualVIN); 

		if (posLin == -1)
			cout << "You do not have a car with the VIN Number 2873644922.\n";
		else 
		{
			cout << "You do have a car on the lot with the VIN Number 2873644922.\n";
		}
		cout << "_______________________________________________________\n";
	// END MANUAL LINEAR SEARCH FOR VIN NUMBER

	// Get the VIN to search for

	 // LINEAR SEARCH FOR VIN NUMBER
		cout << "Enter a VIN number to search for: ";
		cin >> desiredVIN;

	// Linear Search for VIN Number
		pos = search(Car_array, SIZE, desiredVIN); 

		if (pos == -1)
			cout << "You do not have a car with the VIN Number " << desiredVIN << ".\n";
		else 
		{
			cout << "You do have a car on the lot with the VIN Number " << desiredVIN << ".\n";
		}
		cout << "_______________________________________________________\n";

	 // END LINEAR SEARCH FOR VIN NUMBER
	
	// Loop to display car details
		for (int x=0; x<9; x++) {
			Car_array[x].car_details();
		}

		cout << "_______________________________________________________\n";


		//Selection Sort

		cout << " This is the Array of Cars in a selection sort!!\n\n";

		//Sort the Array
		selectionSort(Car_array, SIZE, Car::getMileage);

		//Display 
		showArray();
		
		//Show Array

		void showArray();
		{
			for (int x=0; x<9; x++) {
					Car_array[x].car_details();
				}
		}
		return 0;

}
I changed my code up, here is the code and errors!

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
#include "CarClass.h"
using namespace std;

//Set up Search
int search(Car object[], int size, int value)
{
   int index = 0;         // Used as a subscript to search array
   int position = -1;     // Used to record position of search value
   bool found = false;    // Flag to indicate if the value was found

   while (index < size && !found)
   {
      if (object[index].getVIN() == value) // If the value is found
      {
         found = true;          // Set the flag
         position = index;      // Record the value's subscript
      }
      index++;                  // Go to the next element
   }
   return position;             // Return the position
}// End search


int search(Car[], int, int);
void selectionSort(Car[], int);
void showArray(Car[], int);

int main() {
       
    const int SIZE = 9;
           
    //Array of 9 cars
    Car Car_array[SIZE] = { Car("Porsche", "911", "Silver", 2005, 18990, 1237362727),
                            Car("Ford", "Mustang", "Red", 2007, 49842, 7337372239),
                            Car("Chevrolet", "Beretta", "Black", 1989, 90332, 2873644922),
                            Car("Ford", "Focus", "White", 2008, 150, 9236498273),
                            Car("Voltzwagon", "Jetta", "Black", 2006, 28002, 4673992056),
                            Car("Rolls Royce", "Ghost", "Silver", 2005, 10000, 9292983855),
                            Car("Mazda", "626", "Blue", 2002, 84754, 7364646463),
                            Car("Toyota", "Camry", "Red", 2004, 50332, 2133737227),
                            Car("Bugatti", "Veyron 16.4", "White", 2010, 5, 5712893401)};

   
    long long int manualVIN= 2873644922;
    long long int desiredVIN;
    int posLin; // Used to search for VIN 2873644922
    int pos;  // Used for when user wil input the vin they want to search

    //MANUAL LINEAR SEARCH FOR VIN NUMBER
   
        posLin = search(Car_array, SIZE, manualVIN);

        if (posLin == -1)
            cout << "You do not have a car with the VIN Number 2873644922.\n";
        else
        {
            cout << "You do have a car on the lot with the VIN Number 2873644922.\n";
        }
        cout << "_______________________________________________________\n";
    // END MANUAL LINEAR SEARCH FOR VIN NUMBER

    // Get the VIN to search for

     // LINEAR SEARCH FOR VIN NUMBER
        cout << "Enter a VIN number to search for: ";
        cin >> desiredVIN;

    // Linear Search for VIN Number
        pos = search(Car_array, SIZE, desiredVIN);

        if (pos == -1)
            cout << "You do not have a car with the VIN Number " << desiredVIN << ".\n";
        else
        {
            cout << "You do have a car on the lot with the VIN Number " << desiredVIN << ".\n";
        }
        cout << "_______________________________________________________\n";

     // END LINEAR SEARCH FOR VIN NUMBER
   
    // Loop to display car details
        for (int x=0; x<9; x++) {
            Car_array[x].car_details();
        }

        cout << "_______________________________________________________\n";


        //Selection Sort

        cout << " This is the Array of Cars in a selection sort!!\n\n";

            // Sort the array
    selectionSort(Car_array, SIZE);
   
    // Display the values again
    cout << "The sorted values are\n";
    showArray(Car_array, SIZE);


        return 0;

}

void selectionSort(int array[], int size)
{
    int startScan, minIndex, minValue;

    for (startScan = 0; startScan < (size - 1); startScan++)
    {
        minIndex = startScan;
        minValue = array[startScan];
        for(int index = startScan + 1; index < size; index++)
        {
            if (array[index].VIN < minValue)
            {
                minValue = array[index];
                minIndex = index;
            }
      }
        array[minIndex] = array[startScan];
        array[startScan] = minValue;
    }
}

void showArray(int array[], int size)
{
    for (int count = 0; count < size; count++)
        cout << array[count] << " ";
    cout << endl;
}


ERRORS:

1> \car.cpp(115): error C2228: left of '.VIN' must have class/struct/union

1> type is 'int'

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========






This part of the code works, I just need to figure out how to add a sectional sort to it based of off mileage.

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
#include "CarClass.h"
using namespace std;

//Set up Search 
int search(Car object[], int size, int value)
{
   int index = 0;         // Used as a subscript to search array 
   int position = -1;     // Used to record position of search value 
   bool found = false;    // Flag to indicate if the value was found 

   while (index < size && !found)
   {
      if (object[index].getVIN() == value) // If the value is found
      {
         found = true;          // Set the flag 
         position = index;      // Record the value's subscript 
      }
      index++;                  // Go to the next element 
   }
   return position;             // Return the position
}// End search 

//Sort Array
void selectionSort(array[], int size)

{
int startScan, minIndex, minValue;

for (startScan = 0; startScan < (size - 1); startScan++)
{
	minIndex = startScan;
	minValue = array[startScan];
		for(int index = startScan + 1; index < size; index++)
	{
		if (array[index].VIN < minValue)

	{
		minValue = array[index];
		minIndex = index;
	}
	}
		array[minIndex] = array[startScan];
		array[startScan] = minValue;
	}
	}


int search(Car[], int, int);
void selectionSort(array[], int);
void showArray();
int main() {
        
	const int SIZE = 9;
			
	//Array of 9 cars
	Car Car_array[SIZE] = { Car("Porsche", "911", "Silver", 2005, 18990, 1237362727), 
							Car("Ford", "Mustang", "Red", 2007, 49842, 7337372239),
							Car("Chevrolet", "Beretta", "Black", 1989, 90332, 2873644922),
							Car("Ford", "Focus", "White", 2008, 150, 9236498273),
							Car("Voltzwagon", "Jetta", "Black", 2006, 28002, 4673992056),
							Car("Rolls Royce", "Ghost", "Silver", 2005, 10000, 9292983855),
							Car("Mazda", "626", "Blue", 2002, 84754, 7364646463),
							Car("Toyota", "Camry", "Red", 2004, 50332, 2133737227),
							Car("Bugatti", "Veyron 16.4", "White", 2010, 5, 5712893401)};

	
	long long int manualVIN= 2873644922;
	long long int desiredVIN;
	int posLin; // Used to search for VIN 2873644922
	int pos;  // Used for when user wil input the vin they want to search

	//MANUAL LINEAR SEARCH FOR VIN NUMBER
	
		posLin = search(Car_array, SIZE, manualVIN); 

		if (posLin == -1)
			cout << "You do not have a car with the VIN Number 2873644922.\n";
		else 
		{
			cout << "You do have a car on the lot with the VIN Number 2873644922.\n";
		}
		cout << "_______________________________________________________\n";
	// END MANUAL LINEAR SEARCH FOR VIN NUMBER

	// Get the VIN to search for

	 // LINEAR SEARCH FOR VIN NUMBER
		cout << "Enter a VIN number to search for: ";
		cin >> desiredVIN;

	// Linear Search for VIN Number
		pos = search(Car_array, SIZE, desiredVIN); 

		if (pos == -1)
			cout << "You do not have a car with the VIN Number " << desiredVIN << ".\n";
		else 
		{
			cout << "You do have a car on the lot with the VIN Number " << desiredVIN << ".\n";
		}
		cout << "_______________________________________________________\n";

	 // END LINEAR SEARCH FOR VIN NUMBER
	
	// Loop to display car details
		for (int x=0; x<9; x++) {
			Car_array[x].car_details();
		}

		cout << "_______________________________________________________\n";


		//Selection Sort

		cout << " This is the Array of Cars in a selection sort!!\n\n";

		//Sort the Array
		selectionSort(Car_array, SIZE);

		//Display 
		showArray();
		
		//Show Array

		void showArray();
		{
			for (int x=0; x<9; x++) {
					Car_array[x].car_details();
				}
		}
		return 0;

}
Ok guys my teacher assisted me on this with some pseudo-code, and I am not sure why this is not working! I will post the pseudo-codehe sent me, then I will post what I put as that code, and I will include all of my current code.

pseudo-code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
car temp =0;
//we'll stop at size-1 vs size because we're comparing i to the one following it.  At size -1, it'll be sorted.
for (i = 0; i<size-1; i++;)
{
   //k starts at i+1 because we're comparing i with the ones after it.
   //if we started k at 0, we'd just be comparing an object to itself car[0]>car[0]?
   for (k=i+1; k<size; k++;)
   {
        //compare them
        if mileage of the car at i > than the mileage of the car at k
        {
             move the car[i] into the temporary placeholder so you don't lose it
             move the lower valued car[k] to car[i]'s slot
             move the temporary placeholder car to car[k]'s old slot
        }
        increment to the next car[k]
    }
    increment to the next car[i] and repeat
} 


my interpretation:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
		//Selection Sort

		cout << " This is the Array of Cars in a selection sort!!\n\n";

		temp = 0;
		for (int i = 0; i < SIZE-1; i++)
		{
			for (int k = i+1; k < SIZE; k++)
			{
				if (i > k)
					(i = temp;
					k = i;
					temp = k;
				else {
					i = 0;
				}
			}
		}

		int getSort() {
			return sort;
		}




Current code

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
#include "CarClass.h"
using namespace std;

//Set up Search
int search(Car object[], int size, int value)
{
   int index = 0;         // Used as a subscript to search array
   int position = -1;     // Used to record position of search value
   bool found = false;    // Flag to indicate if the value was found

   while (index < size && !found)
   {
      if (object[index].getVIN() == value) // If the value is found
      {
         found = true;          // Set the flag
         position = index;      // Record the value's subscript
      }
      index++;                  // Go to the next element
   }
   return position;             // Return the position
}// End search


int search(Car[], int, int);
void selectionSort(Car[], int);
void showArray(Car[], int);

int main() {
       
    const int SIZE = 9;
           
    //Array of 9 cars
    Car Car_array[SIZE] = { Car("Porsche", "911", "Silver", 2005, 18990, 1237362727),
                            Car("Ford", "Mustang", "Red", 2007, 49842, 7337372239),
                            Car("Chevrolet", "Beretta", "Black", 1989, 90332, 2873644922),
                            Car("Ford", "Focus", "White", 2008, 150, 9236498273),
                            Car("Voltzwagon", "Jetta", "Black", 2006, 28002, 4673992056),
                            Car("Rolls Royce", "Ghost", "Silver", 2005, 10000, 9292983855),
                            Car("Mazda", "626", "Blue", 2002, 84754, 7364646463),
                            Car("Toyota", "Camry", "Red", 2004, 50332, 2133737227),
                            Car("Bugatti", "Veyron 16.4", "White", 2010, 5, 5712893401)};

   
    long long int manualVIN= 2873644922;
    long long int desiredVIN;
    int posLin; // Used to search for VIN 2873644922
    int pos;  // Used for when user wil input the vin they want to search
    int temp;
    int sort;
    //MANUAL LINEAR SEARCH FOR VIN NUMBER
   
        posLin = search(Car_array, SIZE, manualVIN);

        if (posLin == -1)
            cout << "You do not have a car with the VIN Number 2873644922.\n";
        else
        {
            cout << "You do have a car on the lot with the VIN Number 2873644922.\n";
        }
        cout << "_______________________________________________________\n";
    // END MANUAL LINEAR SEARCH FOR VIN NUMBER

    // Get the VIN to search for

     // LINEAR SEARCH FOR VIN NUMBER
        cout << "Enter a VIN number to search for: ";
        cin >> desiredVIN;

    // Linear Search for VIN Number
        pos = search(Car_array, SIZE, desiredVIN);

        if (pos == -1)
            cout << "You do not have a car with the VIN Number " << desiredVIN << ".\n";
        else
        {
            cout << "You do have a car on the lot with the VIN Number " << desiredVIN << ".\n";
        }
        cout << "_______________________________________________________\n";

     // END LINEAR SEARCH FOR VIN NUMBER
   
    // Loop to display car details
        for (int x=0; x<9; x++) {
            Car_array[x].car_details();
        }

        cout << "_______________________________________________________\n";


        //Selection Sort

        cout << " This is the Array of Cars in a selection sort!!\n\n";

        temp = 0;
        for (int i = 0; i < SIZE-1; i++)
        {
            for (int k = i+1; k < SIZE; k++)
            {
                if (i > k)
                    (i = temp;
                    k = i;
                    temp = k;
                else {
                    i = 0;
                }
            }
        }

        int getSort() {
            return sort;
        }

        return 0;

}


class
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
#include <iostream>
#include <fstream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;

//Vehicle Class
class Car
{
protected:
    string make;  //make
    string model; // model
    string color;  // color
    int    year;  // year
    int mileage;  // miles on car
    long long int VIN;  //Vin Number of car

public:
        //Constructor that will set information for a new car
    void New_vehicle (string a, string b, string c, int d, int e, int f)
    {make = a; model = b; color = c; year = d; mileage = e; VIN = f;}
   
    Car(); //Default constructor
    Car(string, string, string, int, int,int);
    //mutator and accessor functions
    void setMake(string);
    void setModel(string);
    void setColor(string);
    void setYear(int);
    void setMileage(int);
    void setVIN(int);

    string getMake();
    string getModel();
    string getColor();
    int getYear();
    int getMileage();
    long long int getVIN();

    //Check mileage to see if valid
    void valid_mileage(int);
    void car_details();
    string string_car_details();
};

//Sets to default values
Car::Car() {
    make = " ";
    model = " ";
    color = " ";
    year = 0;
    mileage = 0;
    VIN = 0;
}
    // My Vehicle set up(Make, model, color, year, type,bedsize, bike, mileage)
Car::Car(string make, string model, string color, int year, int mileage, int VIN) {
    Car::make =  make;
    Car::model = model;
    Car::color = color;
    Car::year = year;
    valid_mileage(mileage);
    Car::VIN = VIN;
}

void Car::setMake(string make) {
    Car::make = make;
}

void Car::setModel(string model) {
    Car::model = model;
}

void Car::setColor(string color) {
    Car::color = color;
}

void Car::setYear(int year) {
    Car::year = year;
}

void Car::setMileage(int mileage) {
    valid_mileage(mileage);
}

void Car::setVIN(int VIN) {
    Car::VIN = VIN;
}


string Car::getMake() {
    return make;
}
string Car::getModel() {
    return model;
}
string Car::getColor() {
    return color;
}
int Car::getYear() {
    return year;
}
int Car::getMileage() {
    return mileage;
}

long long int Car::getVIN() {
    return VIN;
}


void Car::valid_mileage(int mileage) {
    if (mileage>=0)
        Car::mileage=mileage;
    else {
        Car::mileage=0;
        cout << "WARNING! You have entered invalid mileage!\n";
    }
    }

    void Car::car_details() {
        cout << "The current car is a " << year << ' ' << color << ' '
            << make << ' ' << model << " with " << mileage << " miles.\n\n";
    }

    string Car::string_car_details() {
        stringstream buf;
        buf << "The current car is a " << year << ' ' << color << ' '
        << make << ' ' << model << " with " << mileage << " miles.\n\n";
        return buf.str();
    }


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
		temp = 0;
		for (int i = 0; i < SIZE-1; i++)
		{
			for (int k = i+1; k < SIZE; k++)
			{
				if (i > k)
					(i = temp;
					k = i;
					temp = k;
				else {
					i = 0;
				}
			}
		}


temp is of type car. i and k are of type int. You can't assign them to each other
i and k are meant to serve as indexes into your array of cars. Examples:
1
2
if(cars[i].getMileage() > cars[k].getMileage())
temp = cars[i]


That's not a complete code example, just showing you how to compare and assign.
Also, there's no reason to set i to zero. Get rid of that else clause (wasn't in your instructors psuedo-code either).

Your k for loop should also be up to SIZE-1 as well, not SIZE.
Topic archived. No new replies allowed.