Hi, I am trying to solve a problem. But when I execute it, it is just like halt and not further processing......

Here is my program function

void utility()       // Calculate the utility for users for both period Fun5
{
	double x,y,z,utility1,utility2;
	double delaycost = 10;
	ifstream inFile3,inFile4,inFile5,inFile6;
	ofstream utili1,utili2;

	cout<<"Find out the Utility function for each User in each time Interval:\n";    

	inFile3.open("Utility.txt");
    if(!inFile3) {
	 cout<<"Unable to open Utility file in function utility";
	 exit(1);
	}

	inFile4.open("fixedcost1.txt");
	 if(!inFile4) {
	 cout<<"Unable to open file fixed cost 1 file in utility"<<endl;
	 exit(1);
	}
	
	inFile6.open("prival.txt");
	 if(!inFile6) {
	 cout<<"Unable to open filefixed cost 1 file in utility"<<endl;
	 exit(1);
	}

	utili1.open("expeutil1.txt");             
	while (inFile3 >>x) {
          while (inFile4 >>y){                         
                while (inFile6 >>z){                 
                utility1= x- delaycost- y-z;
                }    
          } 	
  	utili1<<z<<endl;
   }

	utili2.open("expeutil2.txt");
	while (inFile3 >>x) {
          while (inFile4 >>y){                              // calculate each user 
                while (inFile6 >>z){                        // benefit function in period 2  
                utility1= x- delaycost- y-z;                   
                }    
          } 	
  	utili2<<z<<endl;
   }
}

but when I run the program it shows

Find out the Utility function for each User in each time Interval:

and cursur blinking......
but after this it should have compute further operations........
I have each file 1000 of data.

I am using Dev-Cpp 4.9.9.2 on windows 7.


please help me out.......its very urgent....

thanks in advance...

Look carefully at those while loops. See anything strange (wrong) with them?

Take the first set of while loops. The first thing that will happen is that inFile6 will read the entire file while inFile3 and inFile4 remain constant (they won't read any more. After inFile6 reaches end-of-file the inFile6 loop exists and control returns back to inFile4, which will read the next record. The inFile6 will again attempt to do more reads, but it can't because its at end-of-file. The program will go back to inFile4 and read another record then repeat the error all over again. That will continue until inFile4 reaches end-of-file. At that time control returns back to inFile3, which read the next record .

In other words, your program is just a big f**ked up mess :)

commented: It's great when one can use the technical terms +4

Thanks for ur replay
but can u suggest me how I can remove this mess
I just want to read one data at a time from each file and perform operation and store them in onother file.

you might try something like this. That should read one line from each of the three files until one or more reaches end-of-file.

while( inFile3>>x, inFile4>>y, inFile6>>5)
{
    utility1= x- delaycost- y-z;
    util2 << utility1 << endl; // ???? Don't know if this is right or not.
}

Now, what to do about that computation. What are you supposed to do with utility1 after computing its value???

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.