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");
}

You're trying to write to in_stream3, but you never open a file with it.

thanks but ok i did that but it is still not writing to the files. i can see the files exctept receipt.txt and display.txt outside of visual c++ but when i open it nothing is in it. here is the new code with the change. can anyone help

float price,curr_total=0.0;
	int itemnum, wrong=0;    
	ifstream in_stream;
	ofstream in_stream1;
    ifstream in_stream2;
	ofstream in_stream3;	
	ifstream in_stream4;
	ofstream in_stream5;
	in_stream4.open("receipt.txt");
	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
			in_stream3.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_stream4.open("receipt.txt");          // sends items and prices to receipt.txt 
						{
							in_stream5.open("display.txt");
							in_stream5 << setw(5) << "Item number " << setw(5) << " Price " << setw(5) << " Total " << endl;
							in_stream5 << " ------------------------------------------------------------------------ " << endl;
							in_stream5 << setw(5) << itemnum++ << setw(5) << price++ << setw(5) << curr_total << endl;
							in_stream5 << " 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();
	in_stream4.close();
	in_stream5.close();
	system("pause");
}

You've been asked before to use proper formatting. Your code is an absolute mess. Please format your code properly so we can see the flow.

#include<iostream>
#include<fstream>
#include<cstdlib>
#include<iomanip>
#include<stdio.h>
using namespace std;
int main()
{   ifstream in_stream; // reads ITEMSLIST.txt
    ofstream out_stream1; // writes in listWititems.txt
    ifstream in_stream2; // reads PRICELIST.txt
    ofstream out_stream3;// writes in listWitprices.txt
    ifstream in_stream4;// read display.txt
    ofstream out_stream5;// write showitems.txt
    double p1=0.0,p2=0.0;
    int wrong=0;
    int count =0;
    char next;
    in_stream.open("C:\Users\DocumentsITEMLIST.txt", ios::in); // list of avaliable items
        if( in_stream.fail() )// check to see if itemlist.txt is open
            {
               wrong++;   // counts number of errors
               cout << " the error occured here0, you have " << wrong++ << " errors"  << endl;
               cout << "Error opening the file\n" << endl;
               exit(1);
            }
         else{
             cout << " System ran correctly " << endl;
            }
    out_stream1.open("C:\Users\Documents\Visual Studio 2008\Projects\openclose\opencloselistWititems.txt", ios::out); // list of avaliable items
         if( out_stream1.fail() )// check to see if itemlist.txt is open
            {
               wrong++;
               cout << " the error occured here0, you have " << wrong++ << " errors"  << endl;
               cout << "Error opening the file\n" << endl;
               exit(1);
            }
         else{
             cout << " System ran correctly " << endl;
            }
            in_stream2.open("C:\Users\DocumentsPRICELIST.txt", ios::in);             
        if( in_stream2.fail() )// check to see if itemlist.txt is open
            { 
               wrong++;
               cout << " the error occured here0, you have " << wrong++ << " errors"  << endl;
               cout << "Error opening the file\n" << endl;
               exit(1);
            }
         else{
             cout << " System ran correctly " << endl;
            }
        out_stream3.open("C:\Users\Documents\Visual Studio 2008\Projects\openclose\opencloselistWitdollars.txt", ios::out);          
        if( out_stream3.fail() )// check to see if itemlist.txt is open
            {
               wrong++;
               cout << " the error occured here0, you have " << wrong++ << " errors"  << endl;
               cout << "Error opening the file\n" << endl;
               exit(1);
            }
         else{
             cout << " System ran correctly " << endl;
            }   
    in_stream4.open("C:\Users\Documents\Visual Studio 2008\Projects\openclose\openclosedisplay.txt", ios::in);
     if( in_stream4.fail() )// check to see if itemlist.txt is open
            {
               wrong++;
               cout << " the error occured here0, you have " << wrong++ << " errors"  << endl;
               cout << "Error opening the file\n" << endl;
               exit(1);
            }
         else{
             cout << " System ran correctly " << endl;
            }

    out_stream5.open("C:\Users\Documents\Visual Studio 2008\Projects\openclose\opencloseshowitems.txt", ios::out);
      if( out_stream5.fail() )// check to see if itemlist.txt is open
            {
               wrong++;
               cout << " the error occured here0, you have " << wrong++ << " errors"  << endl;
               cout << "Error opening the file\n" << endl;
               exit(1);
            }
         else{
             cout << " System ran correctly " << endl;
            } 
            in_stream.setf(ios::fixed);
        while(!in_stream.eof()) // reads to end of file and gets p1 which is itemnum, clears and gets next character
            {
            in_stream >> p1;
            cin.clear();
            cin >> next;
            }   
            out_stream1.setf(ios::fixed);
        while (!out_stream1.eof())
            {
            out_stream1 << p1;
            cin.clear();
            cin >> next;
            }
            in_stream2.setf(ios::fixed);
    in_stream2.setf(ios::showpoint);
    in_stream2.precision(2);
        while(!in_stream2.eof())  // reads file to end of file
            {
                  rename("ITEMSLIST.txt", "listWititems");
                  in_stream2 >> p1 >> p2 >> count; // gets p1,p2, and count which is current total
                  in_stream2 >> p2;
                  p1 += p2;
                  p2++;
                  cin.clear();  // allows more reading
                  cin >> next;
                  return p1, p2;
             }
            out_stream3.setf(ios::fixed);
    out_stream3.setf(ios::showpoint);
    out_stream3.precision(2);
        while(!out_stream3.eof())  // reads file to end of file
            {
                  rename("PRICELIST.txt", "listWitdollars.txt");
                  out_stream3 << p1 << p2 << count;
                  out_stream3 << p2;
                  p1 += p2;
                  p2++;
                  cin.clear();  // allows more reading
                  cin >> next;
                  return p1, p2;
             }
            in_stream4.setf(ios::fixed);
    in_stream4.setf(ios::showpoint);
    in_stream4.precision(2);
        while (!in_stream4.eof())
        {
            rename("listWitdollars.txt", "display.txt");
            in_stream4 >> p1 >> p2 >> count;
            cin.clear();
            cin >> next;
        }   out_stream5.setf(ios::fixed);
    out_stream5.setf(ios::showpoint);
    out_stream5.precision(2);
        rename("display.txt", "showitems.txt");
        out_stream5 <<setw(5)<< " itemnum " <<setw(5)<<" price "<<setw(5)<<" curr_total " <<endl; // sends items and prices to receipt.txt 
        out_stream5 << setw(5) <<  p1 << setw(5) <<p2 << setw(5)<< count; // sends items and prices to receipt.txt 
        out_stream5 << " You have a total of " << wrong++ << " errors " << endl; 

  in_stream.close(); // closing files.
  out_stream1.close();
  in_stream2.close();
  out_stream3.close();
  in_stream4.close();
  out_stream5.close();
  system("pause");
}

Fix the code tags. Replace all tabs with 4 spaces. Repost, but preview first. Look at the link Walt P posted.

[code]

// code here

[/code]

Embedded code tags don't work. Preview before posting!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.