Writing to output file(.txt) with several functions

I'm currently in an introductory class and I have to write a program to convert dec to hex, binary, and octal using arrays and then write to a text file. I can write to one normally but this is the first time I have with several functions and keep getting compiler errors. Below is the conversion of octal and it will take inputs but I receive errors on outputting and it says outFile is not declared. Sorry for the long length of the copied code and thanks for any help you can provide.

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
 void printReverse (int print [], int ii, ofstream& out){
	for (int z = ii; z >= 0; z--)
		out << print[z];
}

void convertOctal (unsigned int num, ofstream& out){
	int oct[8] ;
	int roct[8];
	oct[0] = num/8;
	roct[0] = num%8;
	
	if (num >  16777215 || num < 0)
		out << "error" << endl;
	else
		for (int i = 1; i < 8; i++){
			oct[i] = (oct[(i-1)]/8);
			roct[i] = (oct[(i-1)]%8);
		}
		for (int i = 0; i < 8; i++){
			if (oct[i] == 0){
				printReverse(roct, i, outFile);
				out << endl;
				break;
			}
		}
}


void convert(string inputFile, string outputFile){
	ifstream inFile;
	inFile.open(inputFile);
	ofstream outFile;
	outFile.open(outputFile);
	int count = 0;
	unsigned int number;
	inFile.getline(number);
	while(!inFile.fail()){
		convertBinary(number,outFile);
		convertOctal(number, outFile);
		convertHex(number, outFile);
		inFile.getline(number);
		count++;
	}
	inFile.close();
	outFile.close();
}
				
int main(){
	string inputFile = "input.txt";
	string outputFile = "output.txt";
        convert(inputFile, outputFile);
	return 0;
}
Either move line 49 & 50 to your function or make them global.
Topic archived. No new replies allowed.