Back to diamond problem

Nov 25, 2014 at 10:38pm
I want to keep the outside stars only and remove the inside diamond shape
to be like

          *
         * *
        *    *
       *       *
      *         *
       *       *
        *    *
         * *
          *
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
using namespace std;

int main() {
    int row;
    // top half
    for (row = 1; row <= 5; row++) {
        for (int space = 1; space <= 5 - row; ++space)
            cout << ' ';
        for (int star = 1; star <= 2 * row - 1; star++)
            cout << '*';
        cout << '\n';
    }
    // bottom half
    for (row = 4; row >= 1; row--) {
        for (int space = 1; space <= 5 - row; space++)
            cout << ' ';
        for (int star = 1; star <= 2 * row - 1; star++)
            cout << '*';
        cout << '\n';
    }
    cout << endl;
    return 0;
}


any help?



appreciate your helping
Last edited on Nov 25, 2014 at 11:37pm
Nov 25, 2014 at 10:39pm
it's diamond in the compiler I don't know why it appear like this here.. I hope you get what I mean anyways

thanks
Nov 25, 2014 at 11:09pm
Use [output][/output] tags to preserve indentation.

So what exactly is the problem? What part of the code is not doing what you want?
Nov 25, 2014 at 11:39pm
Edited
The problem is I dont know how to make it like this
The code shows a fully starred diamond shape
I just want it to be a starred sided diamond (empty from inside)
Nov 25, 2014 at 11:45pm
So instead of printing asterisks everywhere, you'll only want to print 1 or 2 each row. You'll need to look at the parts of the loop that print the asterisks and edit them to only print the asterisks on the edges and print spaces in the center.
Nov 25, 2014 at 11:48pm
Tried.
Couldn't reach the answer.
Last edited on Nov 25, 2014 at 11:55pm
Nov 26, 2014 at 1:31am
Well, I don't intend to do it for you. Look at the loops on 10-11 and 18-19; you only want to print out the first and last asterisk and otherwise print spaces.
Nov 26, 2014 at 6:29am
Thank you, Sir.
Topic archived. No new replies allowed.