Member Avatar for DynamicMember

i have this code,and it works.but after running it closes after milliseconds.anywhere i put "getch()" gives error.what to do?

#include <iostream>
using namespace std;

int main()
{
	int i,j,k;




	for( i = 10; i >= 1; i-- )
	{
		for( j = 1; j < i; j++ )
		{
			cout << " ";
		}

		for( k=10; k >= j*3; k-- )
		{
			cout << "*";
		}

		cout << "\n";
	}



	for( i = 2; i <= 10; i++ )
	{
		cout << " ";

		for( j = 2; j < i; j++ )
		{
			cout << " ";
		}

		for( k = 10; k >= j * 2; k-- )
		{
			cout << "*";
		}


		cout << "\n";
	}


return 0;

}

Recommended Answers

All 3 Replies

getch() is part of the conio.h header, which you haven't included. That's actually a good thing, it really should never be used, it is not a standardized header.

Instead, put a cin.get() directly before your return 0; (Line 46).

.
.
.
cout << "\n";

}
system("PAUSE"); // This will hold the command window from closing.
return 0;
}

Don't use getch that's also the equivalence of getch.

add
<code>#include<conio.h></code>
at the begging

and add
<code>getch();</code>
just before the main's closing brace

commented: Did you even read the thread? -1
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.