I cant seem to figure out why this program wont write to a .txt I commented out the meaning of each step and it looks like i am doing everything correct. If i can get it to write it and goto the following steps.
float price,curr_total=0.0;
int itemnum, wrong=0;
ifstream in_stream;
ofstream in_stream1;
ifstream in_stream2;
ofstream in_stream3;
in_stream.open("itemlist.txt"); // list of avaliable items
in_stream2.open("pricelist.txt");// list of avaliable items and there prices.
while((! in_stream.eof()) && (! in_stream2.eof())) // reads in_stream and in_stream2 until the end of file
{
in_stream1.open("items.txt"); // i need to get the items list which is in this file and check to see if item is in item list
// if so i need to send it to receipt.txt
// read all the prices in the file
// the loop will continue until
// end-of-file is reached.
in_stream2.open("plist.txt"); // opens pricelist.txt
while( in_stream2 >> itemnum >> price )
{
while((price== (price*1.00)) && (itemnum == (itemnum*1)))// if price equals a double than its a price
// itemnum = whole number.
{
cout << itemnum << ' ' << price << '\n'; // gets item number and price
itemnum++; // saves item numbers and counts it
price++; // saves price and counts
curr_total= price++;
cout << curr_total;
in_stream2.open("receipt.txt"); // sends items and prices to receipt.txt
{
in_stream3 << setw(5) << "Item number " << setw(5) << " Price " << setw(5) << " Total " << endl;
in_stream3 << " ------------------------------------------------------------------------ " << endl;
in_stream3 << setw(5) << itemnum++ << setw(5) << price++ << setw(5) << curr_total << endl;
in_stream3 << " You have a total of " << wrong++ << " errors " << endl;
while((price!= (price*1.00)) || (itemnum != (itemnum*1))) // if price ! = 2 double and itemnum != whole num
{
cout << " error " << endl;
wrong++; // keeps track of errors so i can display them after program has run
}
}
}
}
}
in_stream.close(); // closing files.
in_stream1.close();
in_stream2.close();
in_stream3.close();
system("pause");
}