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!
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
}
}