Help with getting rid of comma in last number

I am having difficulties getting rid of comma in last number...Can someone please help me on how I can get rid of the last comma in the last number i greatly appreciate all the help!

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;

int main ()
{
char ch;
int ex;
cout<<"Which excerise? ";
cin>>ex;
cout<<endl;
if (ex == 1)
{
double beg, end;
int num;

cout<<"Enter beginning and ending numbers, seperated by space: "<<endl;
cin>>beg;
cin>>end;
cout<<endl;

for (num=beg; num<=end; ++num)
{
cout<<num<<","<<" ";
}
cout<<endl;
cout<<endl;

cout<<"Enter beginning and ending numbers, seperated by space: "<<endl;
cin>>beg;
cin>>end;
cout<<endl;

for (num=beg; num<=end; num++)
{
cout<<num<<","<<" ";
num+=1;
}
cout<<endl;
cout<<endl;

cout<<"Enter the beginning and largest positive numbers, seperated by space: "<<endl;
cin>>beg;
cin>>end;
cout<<endl;

for (num=beg; num<=end; num)
{
cout<<num<<","<<" ";
num*=-2;
}
cout<<endl;
cout<<endl;
}
You mean decimal place?
Do you mean the commas that separate the numbers? The trick is to print the first number, then print the preceding comma with the next number. The following code should work with 0, 1, or N numbers:
1
2
3
4
5
6
if (beg <= end) {
    cout << num;  // print the first number
    for (num = beg+1; num <= end; ++num) {
        cout << ", " << num;   // print numbers 2 through n
    }
}

Topic archived. No new replies allowed.