Need help with while loop

I'm trying to write a while loop that displays 15 asterisks one at a time. When I run the program it doesn't terminate after 15 repetitions. Can somebody help me?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  		#include <iostream>
	using namespace std;
	int main()
{

	int num=1;

	{
	while(num<=15)
	cout<<"*";
	num++;
	}

	system("pause");
}
***************************************
* the brackets in your code were positioned wrong *
***************************************

#include <iostream>
using namespace std;
int main()
{
int num=1;

while(num <= 15) // while loop

{ // The code need to be enclosed between
cout<<"*";
num++;
} // the brackets in order to terminate the loop after 15 repetitions.

cout<<'\n';
return 0;
}


I dont know why you need a while loop if its just for reasearch/leurning then its fine. but you might want to have a look at a for loop.

here is some extra info:
http://www.tutorialspoint.com/cplusplus/cpp_loop_types.htm
Topic archived. No new replies allowed.