MY Diamond Program

[b][b]hi below is the code of my self made diamond printing program..i am a noob and i am trying to learn programming,,, cox its fun :D ..

BTW the problem is that i am getting this figure as output:


**
****
******
****
**

and i am not getting a sharp head asterik of the diamond...:( :(

can u plz identify the problem...!! i wud b thankful :)





#include<iostream>

using namespace std;
int main ()

{
for ( int i = 0 ; i <= 10 ; i++ )
{
for (int k = 10; k >= i ; k--)
{
cout<<" ";

}
for ( int j = 0 ; j <= i ; j++ )
{
if( j==0)
cout<<" ";
else
cout<<"**";




}
cout<<endl;

}

for ( int i=0 ; i <=10 ;i++)
{
for( int j= 0 ; j <= i ; j++)
{
cout<<" ";
}

for( int k = 10 ; k >= i ; k-- )
{
cout<<"**";
}
cout<<endl;





}

system("pause");
return 0;
}


i would also like to know if it is better to use getch() at the end of the program or system pause ?? i am using Dev Cpp IDE...
sorry the diamond shape would be like this which is being printed.


......**
....****
..******
....****
......**
You need to print spaces in front of the asterisks on all lines except the middle line.

i would also like to know if it is better to use getch() at the end of the program or system pause ??


Neither. cin.get(); is common, but there are lots of other good ways to do it.

i am using Dev Cpp IDE...


Please don't. It's really quite bad. http://www.cplusplus.com/forum/articles/36896/
Last edited on
Well each line you print two more '*' so have a variable to keep track of how many you want to print on that line, starting at two and incrementing it by two until you have the first three lines. Once it hits six you can start to subtract two from each line. As for the spaces on each line, figure out some correlation between how many asterisks to print on that line and how many spaces need to be printed (remember that when your variable for how many asterisks should be print is six you print none, so how does this help?)
i had started by first printing the diamonds in a left aligned triangle...i think dats what the problem is....i should start from the upper triangle and then go to lower..than starting from left to right.....???
Can you just draw for us what you would to be output, its hard to guess. When you're outputting in Console you have no choice but to go from left to right and start at the top line and go down. Read my post, I've made a program like this and its not that difficult.
okay thanks...i finally made the diamond..thanks alot :):)
Topic archived. No new replies allowed.