Stumped

Hello, I'm not asking anyone to write the code for me but maybe someone can give me some pointers on getting started with this assignment? The syntax is giving me fits.

Here are the directions: Write a program using for loops to create the figure below.

<<<<<< ############ >>>>>>
<<<<< ##########** >>>>>
<<<< ########***** >>>>
<<< ####********** >>>
<< ##************* >>
< *************** >

Any thoughts? Really I'm just having trouble with the syntax and how to design the for loops. Thanks!
Last edited on
Think about the relationship between the line number and the number of each of characters in each line.
Hint: You can use either an incrementing loop and subtract, or a decrementing loop for the outer loop.
Ok, this is what I've tried so far. Don't laugh! I'm brand new to this stuff and its very overwhelming to me.

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

int main ()
{
	int  printcount;
	int  symcount=0;
	int  linecount;
	char symbol;
	char print;

	for (linecount=1;linecount<=7; linecount++)
		{
			for (symbol='<'; printcount=(7-linecount);printcount++)
				cout<<symbol<<endl;
	}
	return 0;
}



I realize I've got some variables in there I probably don't need.
You've got the right idea on the outer loop, although it will execute 7 times (there are only 6 lines).

The inner loop has a couple of problems.
1) The first expression in a for loop is meant to initialize the loop count. You're initializing symbol instead.
2) Your endl is inside your inner loop, so each symbol will print on a separate line.

Now, think about adding the #, * and > symbols on each line.
Baby steps here...so I've got code that produces the desired output with the "<" symbol, what approach do I take with the subsequent symbols?

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  printcount;
	int  linecount;
	
	for (linecount=1;linecount<=7; linecount++)
	{
		for (printcount=1; printcount<=(7-linecount);printcount++)
			cout<<"<";
		cout<<endl;
	}
		


}






Okay, you've got the first symbol working.

What happens to the # symbol? It goes from 12, 10, 8, down to 0.
You want another loop, like the existing inner loop, that outputs two # symbols each time.

The asterisks are a little trickier. They go 0, 2, 5, 10, 13, 15 (assuming the example in the OP is transcribed correctly.
Got it! Thanks for your help!

Here's the final code for this POS :)

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
int main ()
{
	int  printcount;
	int  linecount;
	
	for (linecount=1;linecount<=7; linecount++)
	{
		for (printcount=0; printcount<=(6-linecount);printcount++)
		cout<<"<";
		
		for (printcount=0; printcount<=(linecount);printcount++)
			cout<<" ";
		
		for (printcount=0;printcount<(14-(2*linecount));printcount++)
			cout<<"#";
			
		for (printcount=0;printcount<((linecount*2)-2);printcount++)
			cout<<"*";

		for (printcount=0; printcount<=(linecount);printcount++)
			cout<<" ";
			
		for (printcount=0; printcount<=(6-linecount);printcount++)
			cout<<">";
			cout<<endl;
		
	}

}


I have a question though. You mentioned earlier there are only 6 lines, but there are 7;but I couldn't get the output with the "<" and the ">" symbols correct until I changed "linecount" to 6 like you suggested. Is that because those symbols only appeared on 6 of the 7 lines? Dumb question, I know :)
There are only 6 lines, not 7?
Topic archived. No new replies allowed.