Confused when using Pointer to array of structures

I was doing some exercises in my C++ primer plus and one exercise wanted me to use a dynamic array of structures. The program creates a car catalog. The user inputs how many cars they want to catalog. A for loop then assigns Make and YearMade to the appropriate number of cars and lastly, another for loop displays all the cars.

I think I did everything mostly right except for the syntax for accessing the structures. Visual Studio gives me this error when I mouse over code involving accessing the structures like cin >> catalog[i]->yearmade;
The error is: expression must have pointer type
Would using an array of pointers to structures make the code work? If so, then how would I make the Pointer to array of structures work?

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
//CarCatalog.cpp 

#include <iostream>
#include <string>

struct car
{
	std::string make;
	int yearmade;
};

int main()
{
	using namespace std;
	//introduction
	cout << "This program catalogs cars." << endl << endl;

	//input
	cout << "How many cars do you wish to catalog? ";
	int carnumber;
	cin >> carnumber;
	cout << endl;

	//calculations
	car * catalog = new car[carnumber];
	for (int i = 0; i < carnumber; i++)
	{
		cout << "Car #" << i + 1 <<":"<< endl;
		cout << "Please enter the make: ";
		cin >> catalog[i]->make;
		cout << "Please enter the year made: ";
		cin >> catalog[i]->yearmade;
	}

	//output
	cout << "Here is your collection: " << endl;
	for (int i = 0; i < carnumber; i++)
	{
		cout << catalog[i]->yearmade << " " << catalog[i]->make << endl;
	}
	delete catalog;
	cin.get();
	cin.get();
	return 0;
}
Topic archived. No new replies allowed.