Loop reading dat file incorrectly
<p>Goodday,</p>

<p>I have a loop reading a dat file but the loop reads the data incorrectly. My dat file contains the following data</p>

<pre><code>46780976 3750.40
W 250.00
D 1200.00
W 75.00
W 375.00
D 1200.00
I 5.50
W 400.00
W 600.00
D 450.50
W 35.65
</code></pre>

<p>The output should be </p>

<pre><code>Account number: 46780976
Opening balance: R3750.40

Transaction    Amount    Balance Bank costs
Withdrawal     250.00    4000.00
Deposit       1200.00Ct  2800.00
Withdrawal        75.00  2725.00
Withdrawal      1375.00   1350.00
Deposit        1200.00Ct 1550.00
Interest         5.50    1555.50
Withdrawal      400.00   1155.50
Withdrawal      600.00   555.50     25.00
Deposit         450.00Ct 1005.50
Withdrawal       35.65    969.85
Banking costs    25.00    969.60

Closing balance: R969.60
</code></pre>

<p>I get the following </p>

<pre><code>Account number : 46780976

Opening Balance : R 3750.4

Transaction        Amount          Balance         Bank Costs


Withdrawal            250            3500.4
Deposit            0 Ct            3500.4
Interest              0            3500.4

Withdrawal            250            3225.4
Deposit            1200 Ct            4425.4
Interest              0            4425.4

Withdrawal            75            4325.4
Deposit            1200 Ct            5525.4
Interest              0            5525.4

Withdrawal            375            5125.4
Deposit            1200 Ct            6325.4
Interest              0            6325.4

Withdrawal            375            5925.4
Deposit            1200 Ct            7125.4
Interest              0            7125.4

Withdrawal            375            6725.4
Deposit            1200 Ct            7925.4
Interest              5.5            7930.9

Withdrawal            400            7505.9
Deposit            1200 Ct            8705.9
Interest              5.5            8711.4

Withdrawal            600            8086.4
Deposit            1200 Ct            9286.4
Interest              5.5            9291.9

Withdrawal            600            8666.9
Deposit            450.5 Ct            9117.4
Interest              5.5            9122.9

Withdrawal            35.65            9062.25
Deposit            450.5 Ct            9512.75
Interest              5.5            9518.25

Withdrawal            35.65            9457.6
Deposit            450.5 Ct            9908.1
Interest              5.5            9913.6
Bank Costs           25            9888.6            25


Closing Balance : R 9888.6
Press any key to continue . . .
</code></pre>

<p>My code :</p>

<pre><code>do { 
   in_stream &gt;&gt; letter;

if (letter == 'W')

    in_stream &gt;&gt; withdrawal;
    openBalance -= withdrawal;
    cout &lt;&lt; "\nWithdrawal" &lt;&lt; "            "&lt;&lt; withdrawal &lt;&lt; "            " &lt;&lt; openBalance &lt;&lt; endl;
    out_stream &lt;&lt; withdrawal;

if (letter == 'D')

    in_stream &gt;&gt; deposit;
    openBalance += deposit;
    cout &lt;&lt; "Deposit" &lt;&lt;"            "&lt;&lt; deposit &lt;&lt;" Ct" &lt;&lt;"            " &lt;&lt; openBalance &lt;&lt; endl;
    out_stream &lt;&lt; deposit;


if (letter == 'I')

    in_stream &gt;&gt; interest;
    openBalance += interest;
    cout &lt;&lt; "Interest" &lt;&lt;"              "&lt;&lt; interest &lt;&lt;"            " &lt;&lt; openBalance &lt;&lt; endl;
    out_stream &lt;&lt; interest;

 if (openBalance &lt; 1000)
     cout &lt;&lt; "Bank Costs" &lt;&lt;"           "&lt;&lt; bankCost &lt;&lt;"            " &lt;&lt; openBalance &lt;&lt;"            " &lt;&lt; bankCost &lt;&lt; endl;
    openBalance -= bankCost;
    out_stream &lt;&lt; bankCost;

} while(!in_stream.eof());
</code></pre>

<p>Please point me in the right direction</p>

<p>thanks</p>
