What is wrong with this 3*3 array program?

Dear Friends,
I want this code get "t" 9 times from a .txt at desktop and save the acc(t) results in array [3][3] forms in text file in desktop. But while running it shows error at lines 13 and 25. I made a text file in desktop and wrote:
2
3
4
5
6
7
8
9
10

But this code does not work.
I want to see the results in
20 30 40
50 60 70
80 90 100
form.
Should I change any setting in compiler eclipse to read the txt file?
Is the code correct?
should there be any open and close lines?

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

int acc(int x)
{
    return (10*x);
}

int main()
{
    const int n = 9;  //reading 9 items from file, assume the file has upto 9 items
    int array[3][3];
    
    ifstream inputFile("C:/users/spring/Desktop/input.txt");  //ive not checked if the file exists
    ofstream outputFile("C:/users/spring/Desktop/output.txt");
    
    //read from file
    int a;
    for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            inputFile<<a;
            array[i][j] = acc(a);
        }
    }
    
    //print to file
    for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            if(i%3 == 0)
                cout<<endl;
            outputFile<<array[i][j]<<setw(4);
        }
    }
    return 0;
}
closed account (48T7M4Gy)
There is only a warning at line 13 to say that you have declared n but not used it.

As for line 25, it should read inputFile >> a because you have opened an ifstream which reads from the file not to the file.
Topic archived. No new replies allowed.