cin.eof()

This is a discussion on cin.eof() within the C++ Programming forums, part of the General Programming Boards category; I am trying to write a program that cerate’s a in invoice. And i am trying to use cin.eof() for ...

  1. #1
    Registered Abuser Loic's Avatar
    Join Date
    Mar 2007
    Location
    Sydney
    Posts
    115

    cin.eof()

    I am trying to write a program that cerate’s a in invoice. And i am trying to use cin.eof() for the program to recognise when the input file has come to an end…
    Code:
    int main(int argc, char *argv[])
    {
        int quantity, numberOfItems; float price, itemTotal, total=0; string productID;
        
        cout << "PHANTOM COMPAY INVOICE\n\n"
             << "PRODUCT ID   QUANTITY   PRICE   PRICE\n\n";
    
        while (cin.eof())
        {
            cin >> productID >> quantity >> price;         // Read values from invoic.dat
            itemTotal = quantity*price;                    // calculate total cost for items
            cout << productID << setw(18-productID.size()) // display product id
                 << quantity << setw(11)                   // display quantity
                 << price << setw(8)                       // display price for one item
                 << itemTotal << endl;                     // display price for all items 
            total = total + itemTotal;                     // calculate cost of all items
        }
        
        cout << endl
             << setw(34) << "TOTAL: " << total;        // display total cost of all items
            
        return EXIT_SUCCESS;
    }
    And this is the file I am trying to input from.
    Quote Originally Posted by purchase.dat
    Pro123 5 25
    Pro152 4 15
    Pro152 4 24
    Pro152 5 10
    Pro152 4 9
    and I am using this bat file I created to run the program
    Quote Originally Posted by Invoice.bat
    @echo off

    echo PHANTOM COMPAY INVOICE
    echo Makeing Invoice, Output File "Statment.txt"

    invoice.exe < purchase.dat > statment.txt
    pause
    for my output all i get is
    Quote Originally Posted by statment.txt
    PHANTOM COMPAY INVOICE

    PRODUCT ID QUANTITY PRICE PRICE


    TOTAL: 0

  2. #2
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    "I saw a sign that said 'Drink Canada Dry', so I started"
    -- Brendan Behan

    Free Compiler: Visual C++ 2005 Express
    If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?

  3. #3
    Registered Abuser Loic's Avatar
    Join Date
    Mar 2007
    Location
    Sydney
    Posts
    115
    Quote Originally Posted by ChaosEngine View Post
    Cheers mate, Found what i needed there

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What does cin.eof() do?
    By Yin in forum C++ Programming
    Replies: 2
    Last Post: 04-11-2002, 11:28 AM
  2. MS VC++ cin.eof ignoring first ^Z. What up?
    By dstocks in forum C++ Programming
    Replies: 1
    Last Post: 01-12-2002, 04:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21