Link to home
Start Free TrialLog in
Avatar of blacksteel4life
blacksteel4life

asked on

draw a diamond

Thanks Snoegler.

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


              *
             ***
            *****
           *******
            *****
             ***
              *
             
Avatar of jonnin
jonnin

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



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
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.
Avatar of blacksteel4life

ASKER

Will try a different approach
ASKER CERTIFIED SOLUTION
Avatar of snoegler
snoegler

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This was more a joke than a solution (you won't present this to your teacher, will you?).
BTW: Please post comments instead of editing the question.
Yes, please post comments instead of editing!

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

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"

comment(s) as an answer.

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: https://www.experts-exchange.com/commspt/


PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner