I'm trying to append the end of the file treatments.txt but am unsure how to use the while loop correctly!! Any suggestions?? I tried boolean with the whiles aswell but can't seem to get it to work either. Like asking do you want to continue adding treatments and if yes set bool to false and exit while statement.

void enterTreatments( T * treatArray, int numTreatments)
		int treatmentNumber = -1;
		ofstream outfile;
    //    while(numTreatments > treatmentNumber)
	for (int i = 0; i < numTreatments; i++)
	    cout << "Enter treatment ID" << endl;
	    cin  >> treatArray[i].treatmentID;
	    outfile << treatArray[i].treatmentID;
		cout << "Enter treatment Description" << endl;
		outfile << treatArray[i].treatmentDescription;
		cout << "Enter cost for treatment" << endl;
		cin  >> treatArray[i].cost;
		outfile << treatArray[i].cost;
		cout << "Enter number of required sessions" << endl;
		cin  >> treatArray[i].noOfRequiredSessions;
		outfile << treatArray[i].noOfRequiredSessions;
		treatArray[i].costPerSession = treatArray[i].cost/treatArray[i].noOfRequiredSessions;
		//cout << "Enter cost per session " << endl;
		//cin >> treatArray[i].costPerSession;
		cout  << "Cost for each session is = " ;
		cout  << treatArray[i].costPerSession << endl;
		outfile << treatArray[i].costPerSession;


>Any suggestions??
Open the file with the ios::app mode, then you don't have to worry about it. Every write will be an append.

This question has already been answered. Start a new discussion instead.