void budgetCheck() {
for (int i = 0; i != 100; i++) {
if (arrayTotalCost[i][2] > arrayTotalCost[i][0]) {
outputValidPackage(i);
}
else outputInvalidPackage(i);
}
}
void outputValidPackage(int i) {
fstream validPackage;
if (validFirst = false) {
validPackage.open("requestOutValid.txt");
validFirst == true;
}
validPackage << "Total cost is : " << arrayTotalCost[i][0] << " , the budget is : " << arrayTotalCost[i][2] << endl;
validPackage << "The Sydney to Tokyo flight is on day " << flightTicketArray[i][1] << " and costs " << flightTicketArray[i][3] << endl;
validPackage << "The Tokyo to Sydney flight is on day " << flightTicketArray[i][2] << " and costs " << flightTicketArray[i][4] << endl;
validPackage << "A " << hotelArray[i][3] << " star hotel, from day " << hotelArray[i][1] << " to " << hotelArray[i][2] << " will cost " << hotelArray[i][4] << endl;
}
void outputInvalidPackage(int i) {
fstream invalidPackage;
if (invalidFirst == false) {
invalidPackage.open("requestOutInvalid.txt");
invalidFirst = true;
}
invalidPackage << "Package is invalid" << endl << endl;
}
The goal of the code is to take in requests from a text file, and then output the valid and invalid requests into separate text files.
Everything else in the code is working.
I would expect 100 cases between the two text files. But only one is outputting. I am not sure why, the outputted case is seemingly random but the same one every time. The 92nd case. It is not the last valid package or the first invalid. Though it is a valid case.
EDIT : changed = to == . Now one case is printed to both files.