Using Functions & Files!!

Last edited on
Where is your ReadData function?
This is what I've come with so far but I am having so many problems and don't know what to do, I need some advice.

Please post instead what compiler error messages or unexpected output you get so we can determine faster what are the errors.

Thank you
The problem is how to read from the file using functions and how to read the data .. etc.. I am most probably getting garbage from that
Ok, so the simplest way to read a data assuming your text pattern and function prototype is :

void ReadData(ifstream& fin, string& name , int& id, float &grossIncome )
    // ...
    if( getline( fin, name ) )
        fin >> id >> grossIncome;



I'm not sure how you will print the datas since if you call Print function( which only accepts a single type parameter of name, Id etc.. ) it will just print again everything messing your screen.

A nicer alternative is to make an array on main, pass it to the readFile function and store the input in the array parameter, pass the array again to other functions and do other calculations, etc.. then finally pass it to another function that will print the contents of the array...

Hope this helps

EDIT: fixed many many typos
Last edited on
Topic archived. No new replies allowed.