[Solved] I don’t want a comma after the last number/value, how do i remove it (c++, loop)


I would do something like this:

char const* sep = ""; // item separator (nothing to begin with)

for(a;a<=b;a++)
{
    if(a%3 == 0 && a%2 != 0)
    {   
        cout << sep << a; // output the separator before the next value
        sep = ", "; // now change it to a comma
    }
}

cout << "."; // finish with a full stop

2

solved I don’t want a comma after the last number/value, how do i remove it (c++, loop)