need help finishing a program

Hello everyone, I am working on a project and I ran into a dead end due to my knowledge. I wrote what I can but I know I'm missing things, I would greatly appreciate some assistance in finishing it. I will write what I need and what I have so far below.

Assignment: I need to write an application that asks the user for an input file name. ( the file that holds the information). And it writes its output to a file called occupations.out
On each line of the input file there is an occupation job title (without blank spaces with at most 30 characters) followed by a floating-point number representing the national average salary. My program should be able to process 20 occupations (so, my arrays will have 20 elements). The contents of a sample input file:
Dentist 110890.0
Drafter 32232.0
and so on.
I need the data to be read from the input file and then put into two parallel arrays. The program sorts the data by wage values from highest to lowest. The program calculates and prints the average and median wage values. Format wages with a $ and exactly two digits to the right of the decimal. Job titles should be aligned to the left, wage values to the right. If the input file has more than 20 occupations in it, do not process the ones after 20.
Again assistance would be most appreciated ^_^

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

using namespace std;

void Occupations(char jobs[20][30]);
void WriteToFile();

int main(){
	WriteToFile();

	return 0;
}

void Occupations(char jobs[20][30]){
	ifstream readFile;
	ofstream writeFile;

	const int NUMBEROFJOBS = 20;
	const int NAMEOFJOB = 30;
	char c;

	readFile.open("Occupations");

	for(int i = 0; i < NUMBEROFJOBS-1;i++){
		for(int j = 0; j < NAMEOFJOB-1;j++){
			readFile.get(c);
			if(c != ' '){
				jobs[i][j] = c;
			}
		}
	}
	readFile.close();
}
void WriteToFile(){
	ofstream out;

	const int NUMBEROFJOBS = 20;
	const int NAMEOFJOB = 30;

	char occ[NUMBEROFJOBS][NAMEOFJOB];

	out.open("output");

	Occupations(occ);

	for(int i = 0; i < NUMBEROFJOBS-1; i++){
		for(int j = 0; j < NAMEOFJOB-1;j++){
			out << occ[i][j];
		}
	}
	out.close();
}

Was that not you who posted this same thing about a week ago under a different name?

http://cplusplus.com/forum/general/84455/

I assume you're still stuck on the sorting part?
Oh no, this is my first time on here, must be someone with same assignment. My main problem is when I run this it doesn't work properly. Sometimes it puts random information but formatted right. To be honest I think I went about this the wrong way but I wanted to get a more experienced person to give me pointers or to possibly fix my code so it will work right. Thanks for the reply.
bump, someone please help I made some changes and I don't know where to throw the error message its suppose to print
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
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

void writeToFile();

void readFile(char titles[][30],double wages[], int NUMBER_OF_JOBS, int JOB_TITLE, int JOB_WAGES);

int main()
{
	cout << "Welcome to job sorting" << endl;
	cout << "Please enter input file name" << endl; 
	writeToFile();



   return(0);
}

void readFile(char titles[][30],double wages[], int NUMBER_OF_JOBS, int JOB_TITLE, int JOB_WAGES){
	ifstream read;

	char test;

	read.open("occupations");
	
	for(int i = 0; i < NUMBER_OF_JOBS-1;i++)
	{
		for(int j = 0; j < JOB_TITLE-1;j++){
			test = read.get();
			if(test != ' '){
				titles[i][j] = test;
			}else{
				for(;j<JOB_TITLE-1;j++){
					titles[i][j] = ' ';
				}
			}
		}
		read >> wages[i];
	}

}

void writeToFile(){
	ofstream write;
	const int JOBS = 20;
	const int MAX_TITLE_LENGTH = 30;
	const int MAX_WAGES_LENGTH = 10;
	char jobs[JOBS][MAX_TITLE_LENGTH];
	double salary[JOBS];

	readFile(jobs,salary,JOBS,MAX_TITLE_LENGTH,MAX_WAGES_LENGTH);

	write.open("output");

	for(int i = 0; i < JOBS-1;i++)
	{
		for(int j = 0; j < MAX_TITLE_LENGTH-1;j++){
			write << jobs[i][j];
		}
			write << setw(10) << right << fixed <<setprecision(2) << showpoint << "$" << salary[i] << endl;
	}
}
Well first off, it says parallel arrays. So don't use a 2D array. That'll make things simpler. What exactly is the issue your having?
Topic archived. No new replies allowed.