Arrays and void functions program question

My teacher said this program doesn't exactly follow the instructions but would not tell me why. Can anyone help out?

Create a program called ArrayNums that calls a void function to create a sequential file for output called arrayNums. It should be put into a for loop using the random number generator to generate 10 integer numbers.

Create an integer array called intArray and pass it to a void function called fillTheArray. In this void function open the arrayNums file as input and read the numbers into the array.

Create another void function called totalTheNums where you will display and total up the numbers. In this module, display the numbers and then after the loop is complete, display the total.

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 <cstdlib>

using namespace std;

void makeArrayFile()
{
	ofstream file;
	//Open file
	file.open("C:/arrayNums");

	for (int i = 0; i<10; i++)
		file << rand() << "\n\r\n";
}
void fillTheArray(int * intArray)
{
	fstream myfile;
	int a, i = 0;
	//Open file
	myfile.open("C:/arrayNums");

	while (myfile >> a)
	{
		intArray[i] = a;
		i++;
	}
	myfile.close();
}

void totalTheNums(int *intArray)
{
	long int total = 0;

	for (int i = 0; i<10; i++)
	{
		cout << "Integer value at index " << i << " is: " << intArray[i] << endl;
		total += intArray[i];
	}
	//Print total of values in array
	cout << "Total of values in intArray: " << total << endl;
}

int main(){

	int intArray[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

	makeArrayFile();
	fillTheArray(intArray);
	totalTheNums(intArray);

	system("pause");
	return 0;
}
Topic archived. No new replies allowed.