cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
C++ problem stopping cout function
C++ problem stopping cout function
Oct 6, 2013 at 5:10am UTC
ninjadude0330
(1)
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;
}
Oct 6, 2013 at 5:23am UTC
TheIdeasMan
(6817)
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
Oct 6, 2013 at 5:27am UTC
Topic archived. No new replies allowed.