1

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;

}
4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by profyou
0

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).

-2

.
.
.
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.

-1

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

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

Votes + Comments
Did you even read the thread?
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.