for loop w/ while statement misadventure

I have a function which, in a perfect world, is supposed to list 9 lines of data about store inventory (string, integers, doubles), and it does now, without any glitches. The world is now perfect. Please send money.(Lots)

// Displaying list function for Reorder Report:
void displayTwo(BizData list[],int numEls)
{
// Variables:
int needed = 0;
int totalNeeded = 0;
double totalCost = 0.00;
double cost = 0.00;
int tally = 0;

cout << setw((SCREEN_WIDTH + strTwo.length())/2)
<< strTwo << endl << endl << endl;
cout.setf(ios::left);
cout << setw(ITEM_COL) << "Item";
cout << setw(MANUF_COL) << "Manufacturer";
cout.unsetf(ios::left);
cout.setf(ios::right);
cout << setw(REQUANT_COL) << "Quantity";
cout << setw(NUM_NORM_COL) << "Minimum";
cout << setw(NEEDED_COL) << "Order";
cout << setw(DOLLAR_COL + CCOST_COL) << "Cost" << endl << endl;
cout.unsetf(ios::right);

for (int i = 0; i < numEls; i++){ // numEls is size of rows of list
if ((list[i].numNorm - list[i].numInStor) > 0){
// while (items need to be ordered)
needed = list[i].numNorm - list[i].numInStor;
totalNeeded += needed;
cost = needed * list[i].pricePer;
totalCost += cost;
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(DOLLAR_PRECISION);
cout.setf(ios::left);
cout << setw(ITEM_COL) << list[i].partName.c_str();
cout << setw(MANUF_COL) << list[i].partManuf.c_str();
cout.unsetf(ios::left);
cout << setw(REQUANT_COL) << list[i].numInStor;
cout << setw(NUM_NORM_COL) << list[i].numNorm;
cout << setw(NEEDED_COL) << needed;
cout.setf(ios::right);
cout << setw(DOLLAR_COL) << "$";
cout.unsetf(ios::right);
cout << setw(CCOST_COL) << cost << endl;
tally ++;
}
}
cout << endl << endl;
cout << "Number of different items to order: " << tally << endl;
cout << "Total number to order: " << totalNeeded << endl;
cout << "Total cost: " << totalCost << endl << endl;
cout << "Press \"Enter\" to continue..." << endl << endl;
cin.get();
cin.get();

}
Last edited on
Topic archived. No new replies allowed.