(UPDATED **Class help**)Input and output to file issue

Hi I'm pretty new to this so please be nice ^.^ but I'm working on a project trying to learn how to input and output to file if anyone can look at this code and give me some pointer on what I am doing wrong would be amazing!

I do have the file in the same folder with the same name the problem is it keeps overriding the input and I haven't really got to the output yet.

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
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

	int	invoiceNumber;
	int clientCount = 1;
	int count = 1;
	int outputInputCount = 0;
	string clientName;
	string teamMemberName;
	string titleName;
	char titleNameSelection;
	char userResponce = 'Y';
	double payRate;
	double invoiceTotal;
	double hoursWorked;
	double teamMemberAmmount;

	void welcome();
	void input();
	void process();
	void output();
	
	
int main()
{
	welcome();
		
	while(userResponce != 'D')
	{	
		if(userResponce == 'N' )
		{
			welcome();
		}
			
	input();
	
	::count = ::count + 1;
	
	};
	
	system("cls");
	output();
	
}

void welcome()
{
	
	system("cls");
	if(:: count == 1)
	{
		cout << "Welcome from Networks For You, please have your infromation ready for the invoice\n";
		cout << "How many clients would you like to enter : " ;
		cin >> clientCount;
		cout << "\nPress enter";
		cin.ignore(10000,'\n');
		cin.clear();
	}
	
	cin.ignore(10000,'\n');
	cin.clear();
	cout << "\nPlease enter your clients name: " ;
	getline (cin,clientName);

	cout << "\nThank you " << clientName << " Now please have your team member information ready!\n";
	cout << "OK lets get started! \nPress enter " << endl;
}

void input()
{	
	cin.ignore(10000,'\n');
	cin.clear();
	cout << "Please enter the team members name: ";
	getline (cin,teamMemberName);

	cout << "\nThank you! \nNow please select the team member " << teamMemberName << "'s job title. Type A: for Project Manager, Type B: for Network Administrator, Type C: for Network Analyst, or Type D: for Network Design Engineer then press enter: ";
	cin >> titleNameSelection;

	while(titleNameSelection != 'A' && titleNameSelection != 'B' && titleNameSelection != 'C' && titleNameSelection != 'D')
		{
			cout << "\nInvalid input please enter A or B or C or D capitalized then press enter!\n";
			cin >> titleNameSelection;
		
		}
		switch(titleNameSelection)
		{
			case 'A':titleName = "Project Manager";
					payRate = 125.00;
					break;
					
			case 'B':titleName= "Network Administrator";
					 payRate = 80.00;
					break;
					
			case 'C':titleName = "Project Manager";
					 payRate= 50.00;
					break;
					
			case 'D':titleName = "Network Design Engineer";
					 payRate = 55.00;
					break;
		}

	cout << "\nPlease enter the amount of hours " << teamMemberName <<" worked. Then press enter: " ;
	cin >> hoursWorked;
	
	cout << "\nIf you have another team member you would like to enter type Y and press enter \nIf you would like to move onto the next client type in N then press enter. \nIf you are completly done type in D and we will finish up!: ";
	cin >> userResponce;
			
	while(userResponce != 'Y' && userResponce != 'N' && userResponce != 'D')
	{
		cout << "Invalid input please enter  Y for another team member N for next client and D to finish capitalized then press enter.\n ";
		cin >> userResponce;
	}
	
	process();
	
	ofstream outputFile;
	outputFile.open("AndrewSmithProjectTwoInput.txt");
			
	if(::count == 1)
	{
			
		outputFile << clientName << endl; 
		outputFile << "Invoice Number: " << invoiceNumber << "\n\n";
		cout << left << setw(19) <<"Team Member Name:" << right << "|" << left << setw(25) << "Title:" << right << "|" << left << setw(7) << "Hours:" << right << "|" << left << setw(14) << "Hourly Rate:" << right << "|" << left << setw(18) << "Team Member Amount:" << endl;
	}
	
	outputFile << left << setw(19) << teamMemberName << right << "|" << left << setw(25) << titleName << right << "|" << left  << "$" << setw(7) << hoursWorked << right << "|" << left  << "$" << setw(14) << payRate << right << "|" << left  << "$" << setw(18) << teamMemberAmmount << endl; 
	::outputInputCount = ::outputInputCount + 1;
			
	if(userResponce == 'N')
	{
		cout << setprecision(2) <<"\nTotal $" << invoiceTotal << endl;
	}
	
	if (userResponce == 'D')
	{
		ofstream outputFile;
		outputFile.close;
	}
	system("cls");
}

void process()
{
	teamMemberAmmount = (hoursWorked * payRate);
	invoiceTotal = invoiceTotal + teamMemberAmmount;
	srand(time(0));
	invoiceNumber = rand() % 99999 + 9999;
}

void output()
{
	::count = 1;
	
	ifstream inputFile;
	inputFile.open("AndrewSmithProjectTwoInput.txt");
	
	while(::clientCount != 0)
	{
	
		while(::count == 1)
		{
			::count = ::count + 1;
		}
		
		while(outputInputCount != 0)
		{	
	
		inputFile >> teamMemberName;
		cout << teamMemberName;
		
		
		outputInputCount = outputInputCount - 1;
		}
		
		::clientCount = ::clientCount - 1;
	}
		
	inputFile.close();
}
Last edited on
A couple of quick suggestions:

First get rid of all of those global variables. Make those variables local to the proper functions and pass variables to and from your functions as required.

Second look at this snippet:
1
2
	cin.ignore(10000,'\n');
	cin.clear();

If the input stream (cin) is in an error state then the ignore() will not be effective. Errors must be cleared before any further operations can be accomplished on that stream.

Third start using the stream constructors when possible and avoid calling the close() function immediately before the stream goes out of scope, let the destructor do it's job.

1
2
3
4
5
6
7
8
9
10
11
12
void output()
{
...
	ifstream inputFile("AndrewSmithProjectTwoInput.txt"); // Just use the constructor instead of the open() function.
        // Always check to see that the "open" operation succeeds.
        if(!inputFile)
           return;


...

}


Next you don't seem to understand that by default when you open() an ofstream the file contents are erased. If you don't want the file to be erased you need to provide the proper open mode. Since you seem to want both read and write operations on the same file you may want to consider using an fstream() instead.

Also you really should try to limit the number of times you open and close a file because constantly opening and closing files can cause significant overhead.




Thank you, good feed back. I'll try and make some revisions and if there's any other question I'll post it.
So I poked around and I feel like I am getting closer, but a fresh set of eyes and some advice would be amazing! I still haven't moved all the variables to local but that is the next step over the weekend.

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

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

	int	invoiceNumber;
	int count = 1;
	int outputInputCount = 0;
	string clientName;
	string teamMemberName;
	string titleName;
	char titleNameSelection;
	char userResponce = 'Y';
	double payRate;
	double invoiceTotal;
	double hoursWorked;
	double teamMemberAmmount;

	void welcome();
	void input();
	void process();
	void output();
	
	ofstream outputFile;
	
	
int main()
{
	outputFile.open("AndrewSmithProjectTwoInput.txt");
	
	welcome();
			
	input();
	
	::count = ::count + 1;
	
	system("cls");
	output();
	
}

void welcome()
{
	system("cls");
	cout << "Welcome from Networks For You, please have your infromation ready for the invoice\n";
}

void input()
{	
char userResponce = 'Y';

while(userResponce != 'D' )
	{	
		cout << "\nPlease enter your clients name: " ;
		cin.clear();
		//cin.ignore(10000,'\n');
		getline (cin,clientName);

		cout << "\nThank you " << clientName << " Now please have your team member information ready!\n";
		cout << "OK lets get started! \n" << endl;
	
		cin.clear();
		//cin.ignore(10000,'\n');
		char userResponce = 'Y';
	
		while (userResponce != 'N' && userResponce != 'd' )
		{
			cout << "Please enter the team members name: ";
			cin.clear();
			//cin.ignore(10000,'\n');
			getline (cin,teamMemberName);

			cout << "\nThank you! \nNow please select the team member " << teamMemberName << "'s job title. Type A: for Project Manager, Type B: for Network Administrator, Type C: for Network Analyst, or Type D: for Network Design Engineer then press enter: ";
			cin >> titleNameSelection;

		
			while(titleNameSelection != 'A' && titleNameSelection != 'B' && titleNameSelection != 'C' && titleNameSelection != 'D')
			{
				cout << "\nInvalid input please enter A or B or C or D capitalized then press enter!\n";
				cin >> titleNameSelection;
			
			}
			switch(titleNameSelection)
			{
				case 'A':titleName = "Project Manager";
						payRate = 125.00;
						break;
						
				case 'B':titleName= "Network Administrator";
						 payRate = 80.00;
						break;
						
				case 'C':titleName = "Project Manager";
						 payRate= 50.00;
						break;
						
				case 'D':titleName = "Network Design Engineer";
						 payRate = 55.00;
						break;
			}

			cout << "\nPlease enter the amount of hours " << teamMemberName <<" worked. Then press enter: " ;
			cin >> hoursWorked;
			
			cout << "\nIf you have another team member you would like to enter type Y and press enter \nIf you would like to move onto the next client type in N then press enter. \nIf you are completly done type in D and we will finish up!: ";
			cin >> userResponce;
					
			while(userResponce != 'Y' && userResponce != 'N' && userResponce != 'D')
			{
				cout << "Invalid input please enter  Y for another team member N for next client and D to finish capitalized then press enter.\n ";
				cin >> userResponce;
			}
			cin.ignore(10000,'\n');
			getline (cin,clientName);
			system("cls");	
		}
	}
	
	process();
	
		
	if(::count == 1)
	{
			
		outputFile << clientName << endl; 
		outputFile << "Invoice Number: " << invoiceNumber << "\n\n";
		outputFile << left << setw(19) <<"Team Member Name:" << right << "|" << left << setw(25) << "Title:" << right << "|" << left << setw(7) << "Hours:" << right << "|" << left << setw(14) << "Hourly Rate:" << right << "|" << left << setw(18) << "Team Member Amount:" << endl;
	}
	
	
	outputFile << left << setw(19) << teamMemberName << right << "|" << left << setw(25) << titleName << right << "|" << left  << "$" << setw(7) << hoursWorked << right << "|" << left  << "$" << setw(14) << payRate << right << "|" << left  << "$" << setw(18) << teamMemberAmmount << endl; 
	::outputInputCount = ::outputInputCount + 1;
			
	if(userResponce == 'N')
	{
		cout << setprecision(2) <<"\nTotal $" << invoiceTotal << endl;
	}
	
	system("cls");
}

void process()
{
	teamMemberAmmount = (hoursWorked * payRate);
	invoiceTotal = invoiceTotal + teamMemberAmmount;
	srand(time(0));
	invoiceNumber = rand() % 99999 + 9999;
}

void output()
{
	string nextLine = "";
	
	ifstream inputFile;
	
	inputFile.open("AndrewSmithProjectTwoInput.txt");
	
	while (getline(inputFile, nextLine))
	{
		cout << nextLine << endl;
		
	}	   
}
but a fresh set of eyes and some advice would be amazing! I still haven't moved all the variables to local but that is the next step over the weekend.

IMO the removal of the global variables is probably one of the biggest things you need to accomplish.

Also I note that you open your text file in main as an output file erasing the file contents, unless I missed something I never see where you close this file.

Next try to open the same file in your output() function, as an input file(???). Some operating systems may have problems trying to open the same file twice at the same time.

Next I notice a call to srand() in a function. Normally this function should only be called once and only once. IMO it is better to place this call early in main() outside of any loops and before you need your random numbers.

Thank you!
Here is a little update I am working on the validation for the hoursWorked. Next I am going to incorporate 2 classes but if anyone sees any dramatic errors or bad programming standards please let me know.
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
190
191
192
193
194
195
196
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

	//Declares variables
	int	invoiceNumber;
	int count = 1; //Initializes the Variables
	
void welcome()
{
	system("cls");
	cout << "Welcome from Networks For You, please have your information ready for the invoice\n";
}

double process(float hoursWorked, double payRate)
{
	double teamMemberAmmount = 0.0;
	double invoiceTotal = 0.0;
	
	teamMemberAmmount = (hoursWorked * payRate);
	invoiceTotal = invoiceTotal + teamMemberAmmount;
	invoiceNumber = rand() % 99999 + 9999; // generate a random number for the invoice number 

	return teamMemberAmmount;
}

void input(string clientName, char userResponce, string teamMemberName, char titleNameSelection, string titleName, double payRate, float hoursWorked, double teamMemberAmmount, double invoiceTotal)
{	

ofstream outputFile; //open the file outside the loop to let the user finish all the input and entering the data to the file as they put it in
outputFile.open("AndrewSmithProjectThreeInput.txt");

while(userResponce != 'D' )
	{	
		cout << "\nPlease enter your clients name: " ;
		cin.clear();// using some cin clears beacuse the program was skipping some inputs 
		getline (cin,clientName);

		cout << "\nThank you " << clientName << " Now please have your team member information ready!\n";
		cout << "OK lets get started! \n" << endl;
	
		cin.clear();
		
		userResponce = 'Y'; // this keeps the loop going after the user enthers in the first client
	
		while (userResponce != 'N' && userResponce != 'D' )
		{
			cout << "Please enter the team member's name: ";
			cin.clear();
			getline (cin,teamMemberName);// still need to add the not null validation 

			cout << "\nThank you!\n" << endl;
			cout << "Now please select the team member " << teamMemberName << "'s job title from the following" << endl;
			cout << "Type A: for Project Manager" << endl;
			cout << "Type B: for Network Administrator" << endl;
			cout << "Type C: for Network Analyst" << endl;
			cout << "Type D: for Network Design Engineer" << endl;
			cin >> titleNameSelection;

		
			while(titleNameSelection != 'A' && titleNameSelection != 'B' && titleNameSelection != 'C' && titleNameSelection != 'D')
			{
				cout << "\nInvalid input please enter A or B or C or D then press enter!\n";
				cin >> titleNameSelection;
			
			}
			switch(titleNameSelection)
			{
				case 'A':titleName = "Project Manager";
						payRate = 125.00;
						break;
						
				case 'B':titleName= "Network Administrator";
						 payRate = 80.00;
						break;
						
				case 'C':titleName = "Project Manager";
						 payRate= 50.00;
						break;
						
				case 'D':titleName = "Network Design Engineer";
						 payRate = 55.00;
						break;
			}

			cout << "\nPlease enter the amount of hours " << teamMemberName <<" worked. Then press enter: " ;
			cin >> hoursWorked;
			
				
				if (isalpha(hoursWorked))
				{
					cout << "Invalid input please enter a number" << endl;
					cin >> hoursWorked;
					cin.clear();
					cin.ignore(10000,'\n');
				}
				
			while(hoursWorked < 0 || hoursWorked > 300)
			{
				
				cout << "Invalid input please enter the amount of hours "<< teamMemberName << " Worked" << endl;
				cin >> hoursWorked;
			}
			
			cout << "\n********" << endl;
			cout << "**Menu**" << endl;
			cout << "********" << endl;
			
			cout << "Please type in one of the following choices then press enter" << endl;
			cout << "Y- To enter another team member to this client" << endl;
			cout << "N- To start a new cliet invoice" << endl;
			cout << "D- To finish and print" << endl;
			
			
			//If you have another team member you would like to enter type Y and press enter \nIf you would like to move onto the next client type in N then press enter. \nIf you are completly done type in D and we will finish up!: ";
			cin >> userResponce;
					
			while(userResponce != 'Y' && userResponce != 'N' && userResponce != 'D')
			{
				cout << "Invalid input please enter  Y for another team member N for next client and D to finish capitalized then press enter.\n ";
				cin >> userResponce;
			}
			
			process(0, 0);
	
				
			if(::count == 1)
			{
					
				outputFile << clientName << endl; //sending the data the user just entered to the output file
				outputFile << "Invoice Number: " << invoiceNumber << "\n\n";
				outputFile << left << setw(19) <<"Team Member Name:" << right << "|" << left << setw(25) << "Title:" << right << "|" << left << setw(7) << "Hours:" << right << "|" << left << setw(15) << "Hourly Rate:" << right << "|" << left << setw(18) << "Team Member Amount:" << endl;
				
				::count = ::count + 1;
			}
			
			
			outputFile << left << setw(19) << teamMemberName << right << "|" << left << setw(25) << titleName << right << "|" << left  << "$" << setw(7) << hoursWorked << right << "|" << left  << "$" << setw(14) << payRate << right << "|" << left  << "$" << setw(18) << teamMemberAmmount << endl; 
			
					
			if(userResponce == 'N' || userResponce == 'D' )
			{
				outputFile << "\nTotal $" << invoiceTotal << endl;
			}
			
			
			if(userResponce == 'N')// a statement that will add the invoice titles if the user starts a new client
			{
				::count = 1;
			}
			
			cin.clear();
			cin.ignore(10000,'\n');
			system("cls");	
		}
		
		outputFile << "\n\n";
	}
	
	outputFile.close();
	
	system("cls");
}


void output()
{
	string nextLine = "";
	
	ifstream inputFile;
	
	inputFile.open("AndrewSmithProjectThreeInput.txt");
	
	while (getline(inputFile, nextLine))//output the entire file to the prompt
	{
		cout << nextLine << endl;
		
	}	   
}

int main()
{
	srand(time(0)); 
	
	welcome();
			
	input("",'Y', "", 'A', "", 0, 0, 0, 0); // trying to start the transition to no global variables 
	
	system("cls");
	
	output();
	
}
Last edited on
So now I am going to incorporate classes into my program. I am very new to this and my code does not work but this is what I have so far and what I am trying to accomplish. If there is any advice or some kind of push in the right direction I would really appreciate 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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211

#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

void welcome()
{
	system("cls");
	cout << "Welcome from Networks For You, please have your information ready for the invoice\n";
}

class Process
{
	private:
	
	float hoursWorked;
	double payRate;
	
	public:	
	double teamMemberAmmount = 0.0;
	double invoiceTotal = 0.0;
	
	teamMemberAmmount = (hoursWorked * payRate);
	invoiceTotal = invoiceTotal + teamMemberAmmount;
	invoiceNumber = rand() % 99999 + 9999; // generate a random number for the invoice number 

	return teamMemberAmmount;
}

class Input
{
	private:
		string titleName 
		string clientName
		string teamMemberName 
		char titleNameSelection 
		char userResponce
		float hoursWorked		
		double payRate		 
		double teamMemberAmmount 
		double invoiceTotal
	
	public:
	
	ofstream outputFile; //open the file outside the loop to let the user finish all the input and entering the data to the file as they put it in
	outputFile.open("AndrewSmithProjectThreeInput.txt");

	while(userResponce != 'D' )
		{	
			cout << "\nPlease enter your clients name: " ;
			cin.clear();// using some cin clears beacuse the program was skipping some inputs 
			getline (cin,clientName);

			cout << "\nThank you " << clientName << " Now please have your team member information ready!\n";
			cout << "OK lets get started! \n" << endl;
		
			cin.clear();
			
			userResponce = 'Y'; // this keeps the loop going after the user enthers in the first client
		
			while (userResponce != 'N' && userResponce != 'D' )
			{
				cout << "Please enter the team member's name: ";
				cin.clear();
				getline (cin,teamMemberName);// still need to add the not null validation 

				cout << "\nThank you!\n" << endl;
				cout << "Now please select the team member " << teamMemberName << "'s job title from the following" << endl;
				cout << "Type A: for Project Manager" << endl;
				cout << "Type B: for Network Administrator" << endl;
				cout << "Type C: for Network Analyst" << endl;
				cout << "Type D: for Network Design Engineer" << endl;
				cin >> titleNameSelection;

			
				while(titleNameSelection != 'A' && titleNameSelection != 'B' && titleNameSelection != 'C' && titleNameSelection != 'D')
				{
					cout << "\nInvalid input please enter A or B or C or D then press enter!\n";
					cin >> titleNameSelection;
				
				}
				switch(titleNameSelection)
				{
					case 'A':titleName = "Project Manager";
							payRate = 125.00;
							break;
							
					case 'B':titleName= "Network Administrator";
							 payRate = 80.00;
							break;
							
					case 'C':titleName = "Project Manager";
							 payRate= 50.00;
							break;
							
					case 'D':titleName = "Network Design Engineer";
							 payRate = 55.00;
							break;
				}

				cout << "\nPlease enter the amount of hours " << teamMemberName <<" worked. Then press enter: " ;
				cin >> hoursWorked;
				
					
					if (isalpha(hoursWorked))
					{
						cout << "Invalid input please enter a number" << endl;
						cin >> hoursWorked;
						cin.clear();
						cin.ignore(10000,'\n');
					}
					
				while(hoursWorked < 0 || hoursWorked > 300)
				{
					
					cout << "Invalid input please enter the amount of hours "<< teamMemberName << " Worked" << endl;
					cin >> hoursWorked;
				}
				
				cout << "\n********" << endl;
				cout << "**Menu**" << endl;
				cout << "********" << endl;
				
				cout << "Please type in one of the following choices then press enter" << endl;
				cout << "Y- To enter another team member to this client" << endl;
				cout << "N- To start a new cliet invoice" << endl;
				cout << "D- To finish and print" << endl;
				
				
				//If you have another team member you would like to enter type Y and press enter \nIf you would like to move onto the next client type in N then press enter. \nIf you are completly done type in D and we will finish up!: ";
				cin >> userResponce;
						
				while(userResponce != 'Y' && userResponce != 'N' && userResponce != 'D')
				{
					cout << "Invalid input please enter  Y for another team member N for next client and D to finish capitalized then press enter.\n ";
					cin >> userResponce;
				}
				
				Process;
		
					
				if(::count == 1)
				{
						
					outputFile << clientName << endl; //sending the data the user just entered to the output file
					outputFile << "Invoice Number: " << invoiceNumber << "\n\n";
					outputFile << left << setw(19) <<"Team Member Name:" << right << "|" << left << setw(25) << "Title:" << right << "|" << left << setw(7) << "Hours:" << right << "|" << left << setw(15) << "Hourly Rate:" << right << "|" << left << setw(18) << "Team Member Amount:" << endl;
					
					::count = ::count + 1;
				}
				
				
				outputFile << left << setw(19) << teamMemberName << right << "|" << left << setw(25) << titleName << right << "|" << left  << "$" << setw(7) << hoursWorked << right << "|" << left  << "$" << setw(14) << payRate << right << "|" << left  << "$" << setw(18) << teamMemberAmmount << endl; 
				
						
				if(userResponce == 'N' || userResponce == 'D' )
				{
					outputFile << "\nTotal $" << invoiceTotal << endl;
				}
				
				
				if(userResponce == 'N')// a statement that will add the invoice titles if the user starts a new client
				{
					::count = 1;
				}
				
				cin.clear();
				cin.ignore(10000,'\n');
				system("cls");	
			}
			
			outputFile << "\n\n";
		}
		
		outputFile.close();
		
		system("cls");
}

void output()
{
	string nextLine = "";
	
	ifstream inputFile;
	
	inputFile.open("AndrewSmithProjectThreeInput.txt");
	
	while (getline(inputFile, nextLine))//output the entire file to the prompt
	{
		cout << nextLine << endl;
		
	}	   
}

int main()
{
	srand(time(0)); 
	
	welcome();
			
	Input;
	
	system("cls");
	
	output();
	
}
Last edited on
Topic archived. No new replies allowed.