My file isn't reading

The program is supposed to read my file but for some reason it isn't working. The file is .rtf but .txt has the same effects. I checked to see if the file wasn't opening but it does.
Also, this is on a MAC, if that matters.
Thanks for the help again.

This is the contents of the file:
2 3 50
2 1 75
2 0 40
1 3 25
1 5 10
2 6 50
2 8 300
6 3 100
2 0 30
2 2 10
1 6 100
2 4 30
2 6 200
1 5 10
1 6 100

This is the 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
55
56
57
58
59
60
#include <iostream>
#include <fstream>
#define N 10
using namespace std;

void printStock (float [], int);
float sales (float [], int);


int main()
{
    ifstream myfile;
    myfile.open ("/Users/Soul/Documents/School/CISC/Assignment6/file.rtf");


    float inv[N], cmt;
    int acct, type;

    printStock(inv,N);


     myfile>>type>>acct>>cmt;

    while(myfile){
        if (type == 1){
            inv[acct] += cmt;
            cout << "Deposit: " << cmt;
        }

        else if (type == 2){
            inv[acct] -= cmt;
            cout << "Withdrawal: " << cmt;
        }

        if (inv[acct] < cmt)
                cout << "ERROR: Overdraw" << endl;

        if (type != 1 && type != 2)
            cout << "ERROR: Invalid Transation number" << endl;
    }
    myfile.close();
    printStock(inv,N);
    cout << "Total Income: " << sales(inv,N) << endl;
    return 0;
    }


void printStock(float inv[], int nelts){
    cout << "Car Number            Car Value" << endl;
for (int n = 0; n<nelts; n++)
    cout << n << inv[n] << endl;
return;
}

float sales(float inv[], int nelts){
float sum = 0;
for (int n = 0; n<nelts; n++)
    sum += inv[n];
    return sum;
}


This is the output:
Last login: Mon Nov 10 17:07:55 on ttys000
/Applications/CodeBlocks.app/Contents/MacOS/cb_console_runner DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:. /Users/Soul/Documents/School/CISC/Assignment6/bin/Debug/Assignment6
Christians-MacBook-Pro:~ Soul$ /Applications/CodeBlocks.app/Contents/MacOS/cb_console_runner DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:. /Users/Soul/Documents/School/CISC/Assignment6/bin/Debug/Assignment6
Car Number Car Value
00
10
20
30
40
50
60
70
80
90
Car Number Car Value
00
10
20
30
40
50
60
70
80
90
Total Income: 0

Process returned 0 (0x0) execution time : 0.005 s
Press ENTER to continue.

WHAT IS IT SUPPOSED TO DO?
Sorry
The file is to print the car number (numbers in the middle) and the current value via printStock.

Then if the transaction number (the first column) is a 1, adds to the value of the car number, which is what the array if for. If the transaction number is 2, it subtracts.
If the transaction number is neither, it rejects the transaction and if the number subtracted is higher than the value, it rejects it which prevent a negative value.

The it uses printStock again to give us the final values for each of the cars.
Topic archived. No new replies allowed.