# draw a diamond

Thanks Snoegler.

I was hoping someone could provide some insight as to how I can solve this, not write the code for me. This is my code, but the final result is a half diamond, not a full diamond.

#include <iostream>
#include <stdlib.h>
int main()
{
int size;
int i;
int asterix;
cout << "Enter size: 1-80" << endl;
cin >> size;

if (size > 0 && size < 80)
{

for (int i = 0; i < size; i++)
{
int asterix = ++i;
for (; asterix != 0; asterix--)
{
cout << '*';
}
cout << endl;
}

for (i = size; i > 0; i--)
{
int asterix = --i;
for (; asterix != 0; asterix--)
{
cout << '*';
}
cout << endl;
}
}

system("PAUSE");
return 0;
}

i want to Write a C++ program that will print a diamond(filled with asterisks--see below) using for while and do-while loops in each case(loop)with the size of the diamond should be detemined by the user when the program starts . The size may be any positive odd integer between 1 and 79.

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

###### Who is Participating?

Commented:
#include <stdio.h>
#include <iostream>
using namespace std;

#define c(x) (cout << x)
#define     l(s,w) {for(int z=0;z<s;z++) c(' ');for(z=0;z<w;z++) c('*');c(endl);}

void     diamond(int w)
{
for(int i=2-(w&1);i<=w-((w&1)?2:0);i+=2) l((w-i)/2,i);
for(i-=(w&1)?0:2;i>=2-(w&1);i-=2) l((w-i)/2,i);
}
0

Commented:
int main()
{
cout << "just give me an 'F', I cheated on this homework but now I feel bad about it\n" << endl;
}

0

Commented:
Somebody should build a "diamond class library". This question comes over and over again <LOL>. I am just so mad they asked me to program that in C++.

blacksteel4life
Don't expect too much. Many experts here in EE are not willing to write code for your homework. We are all wiliing to help you if you have specific questions about your problem, but you have to show some effort, too.

======
Werner
0

Commented:
If you've got a half diamond, then ... determine if the number of total lines of the diamond is odd or even. If even, simply use the existing code in reverse direction. If odd, do the same but skip the first printed row.
0

Author Commented:
Will try a different approach
0

Commented:
This was more a joke than a solution (you won't present this to your teacher, will you?).
0

Commented:

You need 2 nested loops.

The outer loop for the lines ... how many lines do you need to print a diamond with size *s?
The inner loop for the chars ... you have to print ' ' and '*' ... how many ' '/'*' do you need for every line?

The ' ' is the part that's missing in your code.

FInd these numbers and then come back ...

Good luck!

======
Werner

0

Commented:
Dear blacksteel4life

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to split betwen

"griessh and snoegler"

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points. The link to the Community Support area is: http://www.experts-exchange.com/commspt/

======
Werner
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.