Thread: Another dat file input thread...

  1. #1
    Registered User
    Join Date
    Oct 2007

    Another dat file input thread...

    Hello everyone!
    I need a little help.
    Basically its about inputing data from a data file.
    i understand how to declare a file and open it but im unsure about how to use the input file itself.

    Well I have to calculate something called finalvalue. Finalvalue is a function that accepts four(4) parameters.

    These parameters come from the input data file.
    How do I pull the data from the data file and put them into the parameter?

    Im trying to give as little info as possible because i dont want you guys doing my homework^^. But if you guys need more info please tell me if you need me to supply some more.

  2. #2
    Registered User
    Join Date
    May 2006
    Well we'd need to know if those four parameters are on a single line or on four separate lines.

  3. #3
    Registered User
    Join Date
    Oct 2007
    its a compound interest problem.
    The four parameters are principle, rate, frequency and years.
    They are on the same line.
    this is how the data in the file looks:the 8 is the number of investments, so there is a loop that goes around 8 times and calles the function 8 times within the loop.
    1000 2.5% 4 10
    10000 5.0% 12 25
    15000 3.5% 2 10
    1000 2.5% 365 10
    10000 10% 1 50
    10000 10% 12 50
    8000 8.0% 12 10
    8000 9.0% 1 10

  4. #4
    Registered User
    Join Date
    Dec 2006
    an ifstream, as its name implies, is a stream, just like cin, and it can be used like how you would use cin. eg.
    std::ifstream file_in("filename.dat");
    int count;
    file_in >> count;
    for (int i = 0; i < count; ++i) {
            int principle, frequency, years;
            std::string rate; //using string because of the &#37; sign
            file_in >> principle >> rate >> frequency >> years;
            //do something with the input
    Last edited by cyberfish; 10-31-2007 at 08:25 PM.

  5. #5
    Registered User
    Join Date
    Oct 2007
    oh ok, thank you, ill try it out.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. Totally confused on assigment using linked lists
    By Uchihanokonoha in forum C++ Programming
    Replies: 8
    Last Post: 01-05-2008, 04:49 PM
  4. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  5. Mutlithreaded file handling
    By nvoigt in forum Windows Programming
    Replies: 11
    Last Post: 06-30-2005, 02:39 PM