How do I get ride of comma in the beginning?

1
2
3
4
5
6
7
8
9
10
11
12
13
void display( string restaurant[],int current_size)
{

	for (int i=0; i < current_size; i++)
	{
			if ( i < current_size)
			{
				cout << ", ";
				cout << restaurant[i];
							
			}
	}
}


so this code displays :

,Arbys, Texas Roadhouse, McDonalds, Burgerking, Zupas, Panda Express

So my question is, there's that comma in the beginning. I can't get rid of it. The program lets me add new restaurants to the ARRAY and I don't have problem with having extra comma at the end, but I just can't seem to get rid of the comma in the beginning. Any ideas?
1
2
3
4
5
6
if ( i < current_size)
			{
                                cout << restaurant[i];
				cout << ", ";
							
			}
ResidentBiscuit,

I did that then there's a trailing comma at the end... how do I then get rid of it?
Jake Jung wrote:
and I don't have problem with having extra comma at the end

I took this as meaning you don't care if there's a trailing comma.

1
2
3
4
5
for(int i = 0; i < size; i++)
{
   if(i != size - 1) cout << restaurant[i] << ", ";
   else cout << restaurant[i];
}
Wow, thank you so much my man. I hope you have a great week. You just saved my life. But seeing how easy it is makes me feel so sick! Hahaha.
No problem, a lot of problems seem easy after you've seen the solution.
Topic archived. No new replies allowed.