draw 3 shapes using looping structures

Hi all, I need to draw 3 shapes and put them into an output file. I'm having problems. Suppose I enter 7 into the console then the shapes need to be like this.

%%%%%%%
%%%%%%%
%%%%%%%
%%%%%%%
%%%%%%%
%%%%%%%
%%%%%%%

&&&&&&&
&&&&&&
&&&&&
&&&&
&&&
&&
&

@
@@
@@@
@@@@
@@@@@
@@@@@@
@@@@@@@


I'm having problems with the looping structure, so if anyone could give their input and maybe throw a little bit of code my way, not asking you to write the program, I just need help and maybe a different view will lead me the right way, i have searched but it didnt help :(

any help is appreciated thanks!



You can use for loops that increment a variable until it is equal to another variable.

For example:

1
2
3
4
for (a=0;a<8;a++)
           {
              //code you want here
            }


That's what the for loop would look like, not for any of these shapes but it's a starting point. It's also going to be as much as I'll post until you show your own code.
Last edited on
ok thanks a lot. I guess I should've shown the code that I have so far. Sorry.
I am very lost, I do not know what to do, I am lost completely.
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
/*
 *
 *
 */

/*
 *
 *
 */


#include <iostream>
#include <fstream>
using namespace std;
int main()
{
	ofstream DataOut; //output file object

	int n, i;
	int j, k;

	DataOut.open("Output.txt"); //open output

	cout<< "enter a number 1-20";
	cin>> n;
if ( n <= 0 || n > 21)
	{
	cout<<" Invalid number. Please type a number between 1-20. ";
	}

	do
	{

	}
	while (n < 0 || n > 20);

  do{
		for (i = 1; i <= n; i++)
		{

			cout << endl;
			for (j = 1; j <= i; j++)
			{
				DataOut << "@\t";
			}
            DataOut << endl;
		}
	 } while (i <= n);


	return 0;
}








this code outputs

@
@ @
@ @ @
@ @ @ @
@ @ @ @ @



This is the last one that I need to do. I know how I can do the middle shape in my examples, the square I'm a little confused on? I am a noob, thanks again for any help.

also if I type in 0 or anything over 20, it doesn't cout please re enter a number 1-20
Last edited on
i found out how to do it. Here is my code just in case anyone else needs to do the same thing in the future.
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

#include <iostream>
#include <fstream>
using namespace std;
int main()
{
	ofstream DataOut; //output file object

	int Num;								//number of characters you want to be displayed in given shape

	const char PERCENT = '%';				// const char %
	const char AT = '@';					//const char @
	const char AND = '&';					//const char &


	DataOut.open("Output.txt"); //open output

	if(DataOut)

	{

		cout<< "The output file was created successfully." <<endl<<endl;
	}

	while (!( Num > 0 && Num < 21))
	{
		cout<< "Please enter a number 1-20.";
		cin>> Num;

		if (Num>20 || Num<1)				//check to see if number is less 1-20 and prompt user to re enter proper number
		{
			cout<< "Invalid number."<<endl;
		}
	}
//square
		for (int i = 0; i < Num; i++)
		{
			for (int j = 0; j < Num; j++)
			{
				DataOut <<  PERCENT ;
		    }

            DataOut << endl;		}


//upside down triangle

	     for (int i = 0; i < Num; i++)
	        {
	            for (int j = Num; j > i; j--)
	                DataOut << AT;
	            DataOut << endl;
	        }
DataOut <<endl;


//regular triangle
        for (int i = 0; i < Num; i++)
        {
            for (int j = 0; j <= i; j++)
                DataOut << AND;
            DataOut << endl;
        }



	return 0;
}



Topic archived. No new replies allowed.