I'm trying to write a piece of code that will only print a comma after an output if there is another output printed out after it. I use
for(int j = 0; j < size; j++)
{
if(price[i][j] > 0)
{
cout << airports[j] << ", ";
}
}
The problem is I don't know how to get rid of the last comma that is added with the last entry in the list. It outputs this:
Airports' destinations:
BUR (3): LAX, SFO, SMO,
LAX (1): BUR,
SFO (2): BUR, SMO,
SMO (2): BUR, SFO,
How do I remove the comma at the end of every output?