# Thread: Input from a file using statistical calculations

1. ## Input from a file using statistical calculations

In my computer class we have an assignment where we are supposed to read from a file the account number, annual interest rate for the account, starting balance, the number of months that the account has been open
the statistics are as follow
ACCT# Int R Balance Months Deposit WithD Deposit
3456 0.03 1256.89 4 0.00 56.00 100.00

WithD Deposit WithD
0.00 100.00 75.00

*One deposit and one Deposit WithD
withdrawal for each month* 200.00 50.00

there are 5 lines just like this one above and i am supposed to figure out the total deposits, total withdrawls, Total interest gained, show the final balance and the account number for each individual line and output them all to a file. If anyone can help me with this i would greatly appreciate it Thanks, Mike

2. ## Input from a file using statistical calculations

In my computer class we have an assignment where we are supposed to read from a file the account number, annual interest rate for the account, starting balance, the number of months that the account has been open
the statistics are as follow
ACCT# Int R Balance Months Deposit WithD Deposit
3456 0.03 1256.89 4 0.00 56.00 100.00

WithD Deposit WithD
0.00 100.00 75.00

Deposit WithD
200.00 50.00

There is one deposit and one withdrawal for each month

there are 5 lines just like this one above and i am supposed to figure out the total deposits, total withdrawls, Total interest gained, show the final balance and the account number for each individual line and output them all to a file. If anyone can help me with this i would greatly appreciate it Thanks, Mike

3. one way is to use an ifstream and the >> operator (assuming there is a space between each piece of data in the file as in your post) to read the material into appropriate variables. Read in the administrative data straight up and use a loop to control how many times you read in deposits and withdrawals, adjusting the balance after reading in each tranaction.

4. Unfortunately i'm not sure to do what you are saying... is there anyway you could take the time to demonstrate what you are talking about... if so i would greatly appreciate it.

5. any code?

first you need to learn file I/O...

clarify you data file... which one is it?

ACCT# Int R Balance Months Deposit WithD Deposit
3456 0.03 1256.89 4 0.00 56.00 100.00
3456 0.03 1256.89 4 0.00 56.00 100.00
3456 0.03 1256.89 4 0.00 56.00 100.00

or

ACCT# Int R Balance Months Deposit WithD Deposit
3456 0.03 1256.89 4 0.00 56.00 100.00
ACCT# Int R Balance Months Deposit WithD Deposit
3456 0.03 1256.89 4 0.00 56.00 100.00
ACCT# Int R Balance Months Deposit WithD Deposit
3456 0.03 1256.89 4 0.00 56.00 100.00

or

3456 0.03 1256.89 4 0.00 56.00 100.00
3456 0.03 1256.89 4 0.00 56.00 100.00
3456 0.03 1256.89 4 0.00 56.00 100.00

//edit: didn't realize you double posted... I copied this into the other post (http://cboard.cprogramming.com/showt...362#post317362)

6. any code?

first you need to learn file I/O...

clarify you data file... which one is it?

ACCT# Int R Balance Months Deposit WithD Deposit
3456 0.03 1256.89 4 0.00 56.00 100.00
3456 0.03 1256.89 4 0.00 56.00 100.00
3456 0.03 1256.89 4 0.00 56.00 100.00

or

ACCT# Int R Balance Months Deposit WithD Deposit
3456 0.03 1256.89 4 0.00 56.00 100.00
ACCT# Int R Balance Months Deposit WithD Deposit
3456 0.03 1256.89 4 0.00 56.00 100.00
ACCT# Int R Balance Months Deposit WithD Deposit
3456 0.03 1256.89 4 0.00 56.00 100.00

or

3456 0.03 1256.89 4 0.00 56.00 100.00
3456 0.03 1256.89 4 0.00 56.00 100.00
3456 0.03 1256.89 4 0.00 56.00 100.00

7. 3578 0.03 904.67 3 0.00 50.00 0.00 0.00 75.00 0.00

the first number is the account number
the second number is the interest rate
the third number is the balance
the fourth number is how many months the account has been open
the fifth, seventh, and ninth are deposits
the sixth, eight and tenth numbers are withdrawals

i have five lines similar to the line at the top of this page, some have a few more deposites but also alternate... these other lines also have acct #'s, interest rates, etc.

thanks

8. 3578 0.03 904.67 3 0.00 50.00 0.00 0.00 75.00 0.00

the first number is the account number
the second number is the interest rate
the third number is the balance
the fourth number is how many months the account has been open
the fifth, seventh, and ninth are deposits
the sixth, eight and tenth numbers are withdrawals

i have five lines similar to the line at the top of this page, some have a few more deposites but also alternate... these other lines also have acct #'s, interest rates, etc.

thanks

9. i would put a letter in front of each, for example:

a3578 i0.03 b904.67 t3 d0.00 w50.00 d0.00 w0.00 d75.00 w0.00

then read through and when you encounter:
a - put in account box
i - put in interest box
b - put in balance box
t - put in time(months) box
d - add to deposits box
w - add to withdrawel box

it would end up something like this (in a loop):
Code:
```...

infile>>account;
infile>>interest;
...```

10. is there any way to incorporate this into a while loop maybe using a .eof as well in order to calculate equations... i am not familiar with the headerchar statement

11. oh sorry i just got an email from my professor stating that i am NOT allowed to change the file that i am gathering input from which means that i can't add letters

12. Originally posted by cuttlefishkarl
3578 0.03 904.67 3 0.00 50.00 0.00 0.00 75.00 0.00

the first number is the account number
the second number is the interest rate
the third number is the balance
the fourth number is how many months the account has been open
the fifth, seventh, and ninth are deposits
the sixth, eight and tenth numbers are withdrawals
If every line always has 10 numbers with above description it's easy to read those numbers
Code:
```while inFile

calculate total deposit etc
print to file```
However, if number of deposits/withdrawals varies one line to another, it's impossible to read it without modification on the input file

13. ## Re: Input from a file using statistical calculations

Originally posted by cuttlefishkarl
In my computer class we have an assignment where we are supposed to read from a file the account number, annual interest rate for the account, starting balance, the number of months that the account has been open
the statistics are as follow
ACCT# Int R Balance Months Deposit WithD Deposit
3456 0.03 1256.89 4 0.00 56.00 100.00

WithD Deposit WithD
0.00 100.00 75.00

*One deposit and one Deposit WithD
withdrawal for each month* 200.00 50.00

there are 5 lines just like this one above and i am supposed to figure out the total deposits, total withdrawls, Total interest gained, show the final balance and the account number for each individual line and output them all to a file. If anyone can help me with this i would greatly appreciate it Thanks, Mike

This is homework. Write a program that *attempts* to solve the problem. If something breaks, and you can't fix it - ask for help. But try to do your own work please.

14. This is NOT homework. It is for a test grade and is not simply graded based on whether i attempted the assignment... thank you but no thank you... if you cant help i understand...

15. use english first:

like alphoide does. Except a little more detail:

while input stream is valid
start while
read how long open which equals how many deposits/wd will follow
for loop using however many months(see above) as terminator
start for loop