Struct/File Problem? Need help!

Okay, so the program I'm working on is too rewrite a program I've already done. The prompt of the first program is:
"Write a program which allows a user to pick a planet and then see the following information on the chosen planet. The user can see as many planets as they want one at a time. All the planet info MUST be hardwired into the program, use structs and have a minimum of two programmer build functions. Planet information needed for each:
Distance of from the sun, period of revolution, rotation period, equatorial diameter, satellite number, and ring number.

I have already built this 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
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
//Library Section
#include <conio.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <ExtraLibrary.h>
#include <vector>
#include <cstdlib>
#include <apmatrix.h>
using namespace std;

//struct section
struct Planet
{	//All measurements are in kilometers!
	string Name;
	double Distance;
	double PoR;
	double Rotation;
	long Diameter;
	int SN;
	int Rings;
};
	

//global var section
char Ans;
int I;
vector<Planet>Planets(9);

//prototype section
void display(int&);
void ask(int&);
void Planetdata(vector<Planet>&);

//main section
void main()
{

	do{
		system("cls");

		Planetdata(Planets);
		ask(I);
		system("cls");
		display(I);
		

		cout<<endl<<endl<<endl;

		cout<<"Would you like to run the program again (Y/N)?"<<endl;
		cin>>Ans;

	}while(Ans=='y'||Ans=='Y');
}

void Planetdata(vector<Planet>&)
{
	Planets[0].Name="Mercury";
	Planets[0].Distance=57.9;
	Planets[0].PoR=.241;
	Planets[0].Rotation=59;
	Planets[0].Diameter=4880;
	Planets[0].SN=0;
	Planets[0].Rings=0;

	Planets[1].Name="Venus";
	Planets[1].Distance=108.2;
	Planets[1].Rotation=.61;
	Planets[1].PoR=243;
	Planets[1].Diameter=12100;
	Planets[1].SN=0;
	Planets[1].Rings=0;

	Planets[2].Name="Earth";
	Planets[2].Distance=149.6;
	Planets[2].PoR=1;
	Planets[2].Rotation=.99;
	Planets[2].Diameter=12756;
	Planets[2].SN=1;
	Planets[2].Rings=0;

	Planets[3].Name="Mars";
	Planets[3].Distance=227.9;
	Planets[3].PoR=1.88;
	Planets[3].Rotation=1.03;
	Planets[3].Diameter=4880;
	Planets[3].SN=2;
	Planets[3].Rings=0;

	Planets[4].Name="Jupiter";
	Planets[4].Distance=778.3;
	Planets[4].PoR=11.86;
	Planets[4].Rotation=.41;
	Planets[4].Diameter=142800;
	Planets[4].SN=16;
	Planets[4].Rings=1;

	Planets[5].Name="Saturn";
	Planets[5].Distance=1427;
	Planets[5].PoR=29.46;
	Planets[5].Rotation=.44;
	Planets[5].Diameter=120660;
	Planets[5].SN=18;
	Planets[5].Rings=1000;

	Planets[6].Name="Uranus";
	Planets[6].Distance=287;
	Planets[6].PoR=84;
	Planets[6].Rotation=.7;
	Planets[6].SN=15;
	Planets[6].Rings=11;

	Planets[7].Name="Neptune";
	Planets[7].Distance=4497;
	Planets[7].PoR=165;
	Planets[7].Rotation=.67;
	Planets[7].Diameter=49528;
	Planets[7].SN=8;
	Planets[7].Rings=4;

	Planets[8].Name="Pluto";
	Planets[8].Distance=5900;
	Planets[8].PoR=248;
	Planets[8].Rotation=6.4;
	Planets[8].Diameter=2290;
	Planets[8].SN=1;
	Planets[8].Rings=0;

}

void ask(int&I)
{
	do{
			cout <<"Please select a number - enter the number leading to the corresponding planet:"<<endl<<endl;
			cout <<"1 - Mercury"<<endl;
			cout <<"2 - Venus"<<endl;
			cout <<"3 - Earth"<<endl;
			cout <<"4 - Mars"<<endl;
			cout <<"5 - Jupiter"<<endl;
			cout <<"6 - Saturn"<<endl;
			cout <<"7 - Uranus"<<endl;
			cout <<"8 - Neptune"<<endl;
			cout <<"9 - Pluto"<<endl;
			cin>>I;

			if(I<1||I>9)
				{
					cout<<"Invalid number, please try again."<<endl;
					getch();
				}

			system("cls");
	    }while(I<1||I>9);
		I--;
}

void display(int&I)
{
		cout<<"Planet Name:"<<endl;
			gotoxy(54,0);
			cout<<Planets[I].Name;
			gotoxy(0,1);
		cout<<"Distance from the Sun (in millions of kilometers):"<< endl;
			gotoxy(54,1);
			cout << Planets[I].Distance;
			gotoxy(0,2);
		cout<<"Revolution (in Earth years): "<<endl;
			gotoxy(54,2);
			cout << Planets[I].PoR;
			gotoxy(0,3);
		cout << "Rotation (in Earth days): "<<endl;
			gotoxy(54,3);
			cout << Planets[I].Rotation;
			gotoxy(0,4);
		cout<<"Equatorial Diameter (kilometers): "<<endl;
			gotoxy(54,4);
			cout << Planets[I].Diameter;
			gotoxy(0,5);
		cout<<"Satellites: "<<endl;
			gotoxy(54,5);
			cout << Planets[I].SN;
			gotoxy(0,6);
		cout<<"Rings: "<<endl;
			gotoxy(54,6);
			cout << Planets[I].Rings;
}



My new assignment is to "rewrite this problem so that all the data is read in from a file called Planets.Dat and place them to the screen. For this program you do know there are 9 sets of data to be read in." This is what I have so far:

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
//Library Section
#include <conio.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <ExtraLibrary.h>
#include <vector>
#include <cstdlib>
#include <fstream>
#include <apmatrix.h>
using namespace std;

//struct section
struct Planet
{	//All measurements are in kilometers!
	string Name;
	double Distance;
	double PoR;
	double Rotation;
	long Diameter;
	int SN;
	int Rings;
};
//global var section
char Ans;
int I;
vector<Planet>Planets(9);
int Choose;
ifstream in_file;
ofstream out_file;

//prototype section
void display(int&);
void ask(int&);
void Planetdata(vector<Planet>&, ofstream&);

void main()
{
	do{
		system("cls");

		Planetdata(Planets, I);

		ask(Choose);

		system("cls");

		display(Choose);

		cout<<"Run program again? (Y/N)"<<endl;
		cin>>Ans;
	   }while(Ans=='y'||Ans=='Y');
}

void Planetdata(vector<Planet>&Planets, int&I)
{
	for(I=0;I<9;I++)
		in_file>>Planets[I];
}

void ask(int&Choose, ifstream&in_file)
{
	do{
			cout <<"Please select a number - enter the number leading to the corresponding planet:"<<endl<<endl;
			cout <<"1 - Mercury"<<endl;
			cout <<"2 - Venus"<<endl;
			cout <<"3 - Earth"<<endl;
			cout <<"4 - Mars"<<endl;
			cout <<"5 - Jupiter"<<endl;
			cout <<"6 - Saturn"<<endl;
			cout <<"7 - Uranus"<<endl;
			cout <<"8 - Neptune"<<endl;
			cout <<"9 - Pluto"<<endl;
			cin>>Choose;
			if(Choose<1||Choose>9)
				cout<<"Not a valid planet choice, please try again. Press any key to try again.";
				getch();
				system("cls");
	}while(Choose<1||Choose>9);
	Choose--;
}

void display(int&Choose)
{

		cout<<"Planet Name:"<<endl;
			gotoxy(54,0);
			cout<<Planets[Choose].Name;
			gotoxy(0,1);
		cout<<"Distance from the Sun (in millions of kilometers):"<< endl;
			gotoxy(54,1);
			cout<<Planets[Choose].Distance;
			gotoxy(0,2);
		cout<<"Revolution (in Earth years): "<<endl;
			gotoxy(54,2);
			cout<<Planets[Choose].PoR;
			gotoxy(0,3);
		cout<<"Rotation (in Earth days): "<<endl;
			gotoxy(54,3);
			cout<<Planets[Choose].Rotation;
			gotoxy(0,4);
		cout<<"Equatorial Diameter (kilometers): "<<endl;
			gotoxy(54,4);
			cout<<Planets[Choose].Diameter;
			gotoxy(0,5);
		cout<<"Satellites: "<<endl;
			gotoxy(54,5);
			cout<<Planets[Choose].SN;
			gotoxy(0,6);
		cout<<"Rings: "<<endl;
			gotoxy(54,6);
			cout<<Planets[Choose].Rings;
}


This doesn't work, and I can't find where I went wrong!
in_file>>Planets[I]; You don't have a stream operator to do this. You will need to overload the operator.
Thank you! I figured it out :)
Topic archived. No new replies allowed.