can someone please help me fix this!!
Sep 25, 2015 at 4:18pm UTC
hey guys I am pretty new to the c++. I wrote this program which should ask me to input the diamond width and lateral offset and it should then produce a diamond shape.
its asking for the diamond width and lateral offset, but its not producing the diamond shape instead its giving me a whole bunch of lines. can someone please correct this code to help produce a solid diamond shape and should be able to input both lateral offset and diamond width. thank you.
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 85 86 87
#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: Amar" << endl;
cin.get();
cin.get();
return 0;
}
Last edited on Sep 25, 2015 at 4:24pm UTC
Topic archived. No new replies allowed.