setw outputting one line differently in a loop

140 Views Asked by At

I'm doing a college assignment, and for whatever reason the first displayed line of text doesn't line up to the following lines, despite it being from a for loop.

void displayInventory(string itemNames[], double itemCost[], int itemNoShip[MAX][2])
{
  cout << endl << left << setw(20)<< "Item Name" 
    << setw(10)<< "cost" 
    << setw(10)<< "No. Stock" 
    << right << setw(25)<< "Shipping (1-Yes 0-no)\n";
    for (int i = 0; i < MAX; i++)
    {
    
    cout << left << setw(20)<< itemNames[i] 
      << setw(10)<< setprecision(2) << fixed << itemCost[i] 
      << setw(10)<< itemNoShip[i][0] 
      << right << setw(25)<< itemNoShip[i][1]<< endl;
    }
}

This code will produce the following output, where the first line is one space over to the right, while the rest of the lines are the same.

enter image description here

it should be displaying the following data in an orderly fashion similar to how the bottom 5 outputs in the image are in line. Sorry I don't know how to format the text to be the same it is in the text file we were provided.

lavender    1.50    40  1

milled soap 1.50    10  1

coconut oil 3.25    8   0

toothpaste  8.45    25  1

silverware  1.50    40  1

dish soap   1.50    10  1
0

There are 0 best solutions below