#include <iostream>
using namespace std;
//functions
int myTriangle();
int tryAgain();
//end of functions
//global variables
int pascalH = 0;
//end of global variables
int main()
{
cout << "\t***Please do not enter very large number***\n\n";
cout << "\t Enter the desired height of triangle: ";
cin >> pascalH;
fflush(stdin);
myTriangle();
tryAgain();
cout << endl;
return 0;
}
int myTriangle()
{
int space = pascalH - 1;
cout << "\n\n\n";
for (int ctr = 0; ctr < pascalH; ctr++)
{
int topH = 1;
for (int z = 0; z <= space; z++)
{
cout << " ";
}
space--;
//cout.width(pascalH - ctr); //another method for space
for(int a = 0; a <=ctr; a++)
{
cout << topH << " ";
topH = topH * ( ctr - a) / ( a + 1);
}
cout << "\n";
}
cout << "\n";
return 0;
}
int tryAgain()
{
string answer[4] = {"Y", "y", "N", "n"};
string decision;
cout << "\n\nTry Again? [y/n]:";
cin >> decision;
fflush(stdin);
if (decision == answer[0] || decision == answer[1])
{
system("CLS");
main();
}
if (decision == answer[2] || decision == answer[3])
{
//window close
}
return 0;
}