C++ problem stopping cout function

i need help with this i can't get this to stop outputting i need the numbers to to output except for the last one i need it put without the comma thanks for your help :D



#include <iostream>
#include <stdlib.h.>
using namespace std;

int main()
{
int counter = 1;

while(counter <= 100)
{
cout << counter << ",";
counter++;

}

return 0;
}
First please always use code tags:

http://www.cplusplus.com/articles/z13hAqkS/


try this:

while(counter < 100)

Realise what causes the loop to finish - it's when the condition becomes false.

Is that what you were after?

EDIT:

IF you know how times it needs to loop, then use a for loop:

1
2
3
for (int a =0; a < 100; ++a) {
    std::cout << a +1 << "\n"
} 
Last edited on
Topic archived. No new replies allowed.