I am creating a diamond but I am having problem. Right now, my output prints out 2 triangles underneath each other (is not displaying in the post correctly). I want to flip the 2nd triangle around to create a diamond shape. However, when I try to mess up with counters in the bottom function, the display messes up. Come someone give me any hints to help me figure out what is the problem? Appreciate it.
Current Output:
-*-
-**-
-****-
-******-
-*-
-**-
-****-
-******-
Expected Output
-*-
-**-
-****-
-******-
-****-
-***-
-*-
#include <iostream>
#include <iomanip>
using namespace std;
int top(int value, int userNumber);
int bottom(int value, int userNumber);
int main()
{
int userNumber;
int value;
int k;
int m;
cout << "Please enter a number: ";
cin >> userNumber;
int j = userNumber;
int o = userNumber;
k = top(j,userNumber);
m = bottom(o,userNumber);
system("PAUSE");
return 0;
}
int top(int value,int userNumber)
{
int k = userNumber;
if (value > 0)
{
cout << setw(value) << "*";
while (k > value)
{
cout << " " << "*";
k--;
}
cout << endl;
value--;
return top(value,userNumber);
}
}
int bottom(int value,int userNumber)
{
int m = userNumber;
if (value > 0)
{
cout << setw(value) << "*";
while (m > value)
{
cout << " " << "*";
m--;
}
cout << endl;
value--;
return bottom(value,userNumber);
}
}