Using a file, structures, passing parameters

I am supposed to use functions outside of main to load a structure of speakers with information from the user, and then access each piece of information from a file. I know there are errors when I try to use pass by reference and when I am trying to use a file. Every line makes sense to me, but I know there are issues and I'm looking for someone to help point me in the direction of my errors so that I may fix them. Yes, some parts are unfinished and I am working on them.

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
  #include <iostream>
#include <fstream>
#include <string>
using namespace std;

/*
Project Name: SpeakersBureau
File Name: SpeakersBureau
		Status: 
Start Date: 09/19/2019
End Date:   09/
		The program is designed to store to, read from, and write to a file with basic information 
		from ten different speakers in a Speaker's Bureau. It has a menu that allows the user to destroy 
		and enter data, edit his or her data, print his or her data, or exit the program. The program 
		makes sure all data is entered else it prints an error message. Functions are delegated by main.

		This program was done entirely by me and no part of this program was plagiarized,
		intentionally or unintentionally, from anybody. I would be held accountable and 
		penalized if any part of this program was plagiarized.
*/

	const int NUM_STRING = 1;
	const int PHONE_SIZE = 10;
	const int NAME_SIZE = 51;
	const int TOPIC_SIZE = 51;

	struct Speakers {
		char fullName[NUM_STRING][NAME_SIZE];
		char phoneNumber[NUM_STRING][PHONE_SIZE];
		char topic[NUM_STRING][TOPIC_SIZE];
		double fee;
	};





	//
	//Open the files
	bool openInFile(fstream &inSpeakerFile, string "input.txt") {
		inSpeakerFile.open("input.txt", ios:in);
		if (!inSpeakerFile.fail()) {
			return true;
		}
		else {
			return false;
		}

	bool openOutFile(fstream &outSpeakerFile, string "output.txt") {
		outSpeakerFile.open("input.txt", ios:out);
		if (!outSpeakerFile.fail()) {
			return true;
		}
		else {
			return false;
		}
}
	//
	//


/* The manageData function includes the menu-driven user interface and delegates
    a few tasks to other functions. If this works, this allows the programmer to encapsulate 
    data away from the main inside of a function named manageData. I used enumeration to make 
	the code easier to read and SENTINEL to initialize userChoice. */
void manageData() {
	enum Data { EXIT, ENTER, EDIT, PRINT };
	const int SENTINEL = -1;
	int userChoice;
	userChoice = SENTINEL;

	do {
		cout << "Press 1 to enter data." << endl << "Press 2 to edit data."
			<< endl << "Press 3 to print data." << endl << "Press 0 to exit." << endl;
		cin >> userChoice;
		if (userChoice == ENTER) {
			enterData();
		}
		else if (userChoice = EDIT) {
			editData();
		}
		else if (userChoice == PRINT) {
			printData();
		}
		else if (userChoice == EXIT) {
			break;
		}
		else {
			cout << "Invalid entry."
		}
	} while (userChoice != EXIT);
	
}

void enterData(fstream &outSpeakerFile, fstream &inSpeakerFile, 
speaker[NUM_SPEAKERS], const int NUM_SPEAKERS, const int NEXT_SPEAKER) {
	int userVal;
	userVal = 0;

	if (int i = 1; i <= NUM_SPEAKERS; i++) {
		cout << "This is speaker " << i << endl;
		cout << "To switch to the next speaker, type 0" << endl;
		cin << userVal;
		
		if (userVal == NEXT_SPEAKER) {
			continue;
		}

		cout << "What is the speaker's full name?" << endl;
		cin >> speaker[i].fullName;
		cout << "What is the speaker's phone number?" << endl;
		cin >> speaker[i].phoneNumber;
		cout << "What is the speaker's topic?" << endl;
		cin >> speaker[i].topic;
		cout << "What are the fees associated with the speaker?" << endl; 
		cin >> speaker[i].fees;

		outSpeakerFile << "Name: "  << speaker[i].fullName << endl;
		outSpeakerFile << "Phone Number: " << speaker[i].phoneNumber << endl;
		outSpeakerFile << "Topic: " << speaker[i].topic << endl;
		outSpeakerFile << "Fees: "  <<speaker[i].fees << endl << endl;

	}
}


void editData(fstream &outSpeakerFile, fstream &inSpeakerFile,
	speaker[NUM_SPEAKERS], const int NUM_SPEAKERS, const int NEXT_SPEAKER) {
	int userVal;
	userVal = 0;

	if (int i = 1; i <= NUM_SPEAKERS; i++) {
		cout << "This is speaker " << i << endl;
		cout << "To switch to the next speaker, type 0" << endl;
		cin << userVal;

		if (userVal == NEXT_SPEAKER) {
			continue;
		}



	}
}


void printData(fstream &outSpeakerFile, fstream &inSpeakerFile,
	speaker[NUM_SPEAKERS], const int NUM_SPEAKERS, const int NEXT_SPEAKER) {
	int userVal;
	userVal = 0;

	if (int i = 1; i <= NUM_SPEAKERS; i++) {
		cout << "This is speaker " << i << endl;
		cout << "To switch to the next speaker, type 0" << endl;
		cin << userVal;

		if (userVal == NEXT_SPEAKER) {
			continue;
		}



	}
}


int main() {
	
	const int NEXT_SPEAKER = 0;
	const int NUM_SPEAKERS = 15;
	Speakers speaker[NUM_SPEAKERS];

	fstream inSpeakerFile;
	fstream outSpeakerFile;
	openInFile(inSpeakerFile, "input.txt");
	openOutFile(outSpeakerFile, "output.txt");
	
	manageData();

	return 0;
}
Would you mind telling us what parts you think have errors and what parts you are just working on?
Using code tags is helpful, thank you.

I know there are errors when I try to use pass by reference and when I am trying to use a file.

We don't know what the errors are, the crystal ball is fogged over.

Tell us what the errors are the compiler spits out. The full errors, not a condensed version please.

Since you are reading data from a file we also need an example of the data the file contains.

In manageData you call enterData(), editData() and printData() functions before you define them, without doing a forward declaration.

Even when you get that fixed each function uses parameters you pass to the functions, yet you call the functions without passing anything.

Your formatting is a mess, making it harder to notice potential problems.
WAY to many errors. Your bool function "openInFile" doesn't end - you're missing a bracket. string "input.txt" is not a valid argument for a function. You can instead say "string name = "input.txt"", but there's no point since you type it out in the function anyway.
Topic archived. No new replies allowed.