arrowhead program

Sep 29, 2012 at 6:14am
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
// Includes
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;

// Main Function
int main()
{
	int x;
	int y;

	cout << "This program wil display an arrowhead on the screen.\n\n";

	for ( x = 1; x <= 7; x = x + 2)
	{
		for ( y = 0; y <= 13; y++)
		{
			cout << "+";
		}
		cout << endl;
	}
	for ( x = 5; x > 0; x = x - 2)
	{
		for ( y = x; y > 0; y--)
		{
			cout << "+";
		}
		cout << endl;
	}
	_getch();

	return 0;


        + 
        +++
        +++++
+++++++++++++
        +++++
        +++
        +
}



This program is meant to display an arrowhead like this, see the bottom of the code for what the arrowhead is suppose to look like.


But im having trouble getting it to display and arrow head, when i run the program it looks like this


+++++++++++++
+++++++++++++
+++++++++++++
+++++++++++++
+++++++++++++
+++
+

any ideas?

PS> I put the arrowhead at the bottom of the code because when i tried to put it below it got messed up for some reason.
Last edited on Sep 29, 2012 at 7:20am
Sep 29, 2012 at 7:30am
1
2
3
4
5
6
7
cout << "Rendering Arrow...\n" << endl;

cout << "\t\t+" << endl;
cout << "\t" << "\\\t++" << endl;
cout << "\t-++++++++++" << endl;
cout << "\t/\t++" << endl;
cout << "\t\t+" << endl;


Result:
1
2
3
4
5
        +
\       ++
-++++++++++
/       ++
        +
Last edited on Sep 29, 2012 at 7:36am
Sep 29, 2012 at 9:10am
ok, im working on my loops is there a way i can make a loop or nested loops for it.
Sep 29, 2012 at 5:22pm
anyone got any ideas?
Last edited on Sep 29, 2012 at 5:59pm
Sep 29, 2012 at 6:20pm
Divide it into three parts .
First part
****+
****++
****+++

Second part
+++++++

Third part
****+++
****++
****+


Make three loops for making the three parts separately.
Substitute asterisk with " "(space).

You have not put space anywhere in your code .
Try using
 
 cout << "  ";

Hope that helps!!
Last edited on Sep 29, 2012 at 6:46pm
Sep 29, 2012 at 6:55pm
It did it helped alot, thank you.
Sep 29, 2012 at 7:00pm
i got the first and third part, how would i make the for loop for the 2nd part
Sep 29, 2012 at 7:11pm
simply add the number of spaces and the arrows in the line below +1
In the above case , it would be 4 + 3 + 1 = 8

1
2
3
4
for(int i=0 ; i<8;i++){
  cout << "+" ;
}
cout << endl;



Last edited on Sep 29, 2012 at 7:12pm
Sep 29, 2012 at 7:26pm
ok heres my new 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
// Includes
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;

// Main Function
int main()
{
	int x;
	int y;

	cout << "This program wil display an arrowhead on the screen.\n\n";

	for ( x = 1; x <= 5; x = x + 2)
	{
		cout << "       ";
		for ( int i = 0; i < 8; i++)
		{
			cout<< "+";
		}
		cout << endl;
		
		for ( y = 1; y < 8; y++)
		{
			cout << "+";
		}
		cout << endl;
	}
	for ( x = 7; x > 0; x = x - 2)
	{
		cout << "       ";
			
		for ( y = x; y > 0; y--)
		{
			cout << "+";
		}
		cout << endl;
	}
	_getch();

	return 0;

        +++++++++
++++++++
        +++++++++
++++++++
        ++++++++
++++++++
        +++++++
        +++++
        +++
        +
}



now i run the program i display this:
Look at the bottom of my code for what i display when i run the program.


i need help with this one alot, i mean i understand what you said, its just i never was good with for loops, so sorry for all the questions!
Last edited on Sep 29, 2012 at 9:02pm
Sep 30, 2012 at 3:42am
for ( x = 1; x <= 5; x = x + 2)
{
cout << " ";
for ( int i = 0; i < 8; i++)
{
cout<< "+";
}
cout << endl;

for ( y = 1; y < 8; y++)
{
cout << "+";
}
cout << endl;
}

try this code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

//For first part
for(int i=0 ; i<3;i++){
   //For spaces
      int k=0;
      while(k<4){
            cout << " ";
             k++; 
      }
   //For + sign
   for(int j=0 ; j<=i ; j++){
       cout << "+";
   }
   cout << endl;
}

//For middle part
....try on your own

//For third part
...try on your own


Try writing comments while making patterns as to what each part is supposed to do . It will help you to understand it later.
Last edited on Sep 30, 2012 at 6:24am
Sep 30, 2012 at 7:23am
O, thank you, i will post back in a couple hours, your right i should put comments in my program to help me understand what im doing better.
Sep 30, 2012 at 7:57am
thank you raman009, that was alot of help, at last i got it, i made the arrows longer, i mean longer going across, heres the code feel free to run it and see how it looks.

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
// Includes
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;

// Main Function
int main()
{
	cout << "This program wil display an arrowhead on the screen.\n\n";

	// For first part
	for (int i = 0 ; i < 3 ; i++)
	{
		// For spaces
		int k = 0;
    
		while (k < 8)
		{
			cout << " ";
			k++; 
		}
		// For + sign
		for (int j = 0 ; j <= i ; j++)
		{
			cout << "+";
		}
		cout << endl;
	}
	// For second part
	for (int l = 0 ; l < 1 ; l++)
	{
		// For + sign
		for (int m = 0 ; m <= 11 ; m++)
		{
			cout << "+";
		}
		cout << endl;
	}
	// For third part
	for (int n = 3 ; n > 0 ; n--)
	{
		// For spaces
		int o = 8;

		while (o > 0)
		{
			cout << " ";
			o--;
		}
		// For + sign
		for (int p = n ; p > 0 ; p--)
		{
			cout << "+";
		}
		cout << endl;
	}
	_getch();

	return 0;
}
Topic archived. No new replies allowed.