First, a little analyze:
The '.' will be always printed and always be last. Which means simplification
if(a<=b)
{
for(a;a<=b;a++)
{
if(a%3==0&&a%2!=0)
{
cout<<a;
if(a<b)
{
cout<< " , ";
}
}
}
cout<< ".";
}
The problem in your code is that
b
will not necessary be printed.
There is many solution around this
- if you print the comma after a number, you need to make sure there will be a next number to print.
- if toy print the comma before a number, you need to make sure it is not the first.