My while
loop won't exit while I'm using eof
to control when it should stop. The input file contains the price and quantity on the same line, and the next line has the same, but of different prices and quantities.
sum = 0
item = 0
in >> price >> quantity;
while (!in.eof())
{
item ++;
total = price * quantity;
sum = sum + total;
cout << setw(20) << left << setfill(' ') \
<< item
<< setw(20) << right << setfill(' ')\
<< price
<< setw(20) << right << setfill(' ')\
<< quantity
<< setw(20) << right << setfill(' ')\
<< total
<< endl << endl;
in >> price >> quantity;
}
The output should show the user each price, quantity and total cost for each item that is in the input file.