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;
}
代码的目标是从文本文件中接收请求,然后将有效和无效请求输出到单独的文本文件中。
代码中的所有其他内容都有效。
我希望两个文本文件之间有100个大小写。但是只有一个正在输出。我不知道为什么,输出的情况看似随机,但每次都一样。第92例。它不是最后一个有效软件包或第一个无效软件包。虽然是有效的情况。
编辑:从=更改为==。现在,一个案例被打印到两个文件中。