Diamond Asterisks Code. Really Need Help!

I am in my 1st month of coding. I know the very basic things about it. This code is way out of my league...
I have to write a code for a diamond of asterisks. It is different than other codes i have seen on here.

It must ask the user to input the width of the diamond and the offset of the diamond. Please take a look at the code i have. Maybe experienced c++ people can help me.

If its ran in c++, i can get it to ask the user for input, but it does not make a diamond. It put many asterisks in lines.

Please help. I know it has to be some small problem but i have spent 4 hours looking for the problem and i do not understand what it could be.

i appreciate it your help!!!


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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
  #include <iostream>

using namespace std;


void a( void );
void s( void );
void n( void );
void pyramid(int,int);
void wedge(int,int);


void a() {cout << "*";}
void s() {cout << " ";}
void n() {cout << "\n";}

void pyramid (int width, int offset)
{
    int count1, count2;
    for (int j=1; j < width; j += 2)
    {
        for (int i = 0; i < offset; i++) a();
        count2 = j;
        count1 = (width - count2)/2;

 {
            for (int i = 0; i < count1; i++) a();
            for (int i = 0; i < count2; i++) s();
            for (int i = 0; i < count1; i++) n();
            }
            }
        n();
    }


void wedge(int width, int offset)
{
    for (int j = 0; j < width; j++)
    {
        for (int i = 0; i < offset; i++) a();

{
            for (int i = 0; i < 1; i++) a();
            for (int i = 0; i < j; i++) s();
            for (int i = 0; i < width - j - 1; i++) n();

        }
        }
        cout << endl;
    }




int main()
{
    int colWidth, latOffset;

    cout << "This is a program for outputting a diamond formation.\n";
    cout << "First you must select an odd number diamond width.\n";
    cout << "Then you must select a lateral offset even or odd.\n";
    cout << " Input diamond width: ";
    cin >> colWidth;

    if (colWidth % 2 == 0)
    {
        cout << "ERROR: You entered an even number.\nThe program is correcting your error\n";
        colWidth +=1;
    }
    cout << "Input lateral offset: ";
    cin >> latOffset;
    cout << "\n";

    pyramid (colWidth, latOffset);
    wedge (colWidth, latOffset);



    cout << "\nAuthor: CZ" << endl;
    cin.get();
    cin.get();
    return 0;
}
Last edited on
Topic archived. No new replies allowed.