LOOP Help!

I'm having trouble on how to close my figure. The diamond should be inside the square . but mine is slightly separated from the top and on the sides. can some one help me. The starting parameter is 7 for the square and X-2 for the diamond inside. Hope you can help me.


Here's the code.. :

------------------------------------------------------------------------

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
#include "stdafx.h"
#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
 
int a,b,x,y,i,j;
cout<<"Input a Number:"<<endl;
cin>>x;
a=x;
if (x<=6) 
{ 
cout<<"You should enter an ODD number, 7 onwards"<<endl;

}
if ((x%2)!=0)
{
for(y=0;y<x;y++){cout<<"*";};
cout<<endl;


for(b=0;b<a-2;b++)
{
cout<<"*";
for(y=0;y<x-2;y++){cout<<" ";};
cout<<"*";
cout<<endl;


}
if ((x%2)!=0)
{
for(i = 0; i < ((x/2 + 1)-2); i++)
{
for(j = i; j < (x/2); j++) 
cout << " ";
for(j = 1; j <= (i*2 + 1); j++) {

if ((j == 1) || (j == (i*2 + 1))) { cout << "*"; }
else { cout << " "; }
}

cout << endl;



}
for(i = (x/2); i > 0; i--)
{
for(j = (x/2 + 1); j > i; j--) 
cout << " ";
for(j = (i*2 - 1); j > 0; j--) {


if ((j == (i*2 - 1)) || (j == 1)) { cout << "*"; }
else { cout << " "; }
}
cout << endl;
}

}
else
cout<<"x should be Odd Number\n";





for (y=0;y<x;y++){cout<<"*";}
cout<<endl;


system ("pause");
return 0;
}
}

------------------------------------------------------------------
Last edited on
please give us an example of output that you expect.
Topic archived. No new replies allowed.