i need help

i'm a beginner. just start programming. just have difficulties in some of the codes. can someone make me a program that reads an
integer value n and a character symbol. the program forms the letter Z by printing n input character symbols on the upper line, n input character symbols on the lower line, and n input character symbols on the diagonal line. if the value of n is less than or equal to 2, the program prints “Cannot create the mark.”.

i will appreciate it very much.

by the way, this is the sample output.

Input a number and a symbol: 5 #
#####
.......#
.....#
..#
#####
Do you want to continue? [y/n] : y
Input a number and a symbol: 4 *
****
.....*
...*
.*
****
Do you want to continue? [y/n] : n
Goodbye

Last edited on
here's my code:



int number, row, space;
char symbol, y, n;

int main()
{

cout << "Input a number and a symbol: ";
cin >> number >> symbol;


if(number>2) {

{

for(row; row<=number; row=row+1) {
for(space=0; space<=number-row; space=space+1)
cout << " ";
cout << symbol;
cout << endl;

}


}
}


else
cout << "Cannot create the mark." << endl << endl << endl;




i can't figure out the first row and the last row to form it a Z.

i need help. thanks
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
#include <iostream>
using namespace std;

int main(){

	int n;
	char c;
	cout << "enter an integer and a character: ";
	cin >> n >> c;

	//print first line of chars. n times c
	for(int i = 0; i < n ; i++)	
		cout << c;
	
	cout << endl;
	
	//print diagonal lines
	int j;
	for(int i = n-1; i > 0; i--){ // how many lines
		for (j = i; j > 0; j--) //how many dots+c in a line
			cout << ".";
		cout << c << endl;	
	}

	//print the last line (same as first line)
	for(int i = 0; i < n ; i++)	
		cout << c;		

	cout << endl;
return 0;
}

/*
enter an integer and a character: 12 w
wwwwwwwwwwww
...........w
..........w
.........w
........w
.......w
......w
.....w
....w
...w
..w
.w
wwwwwwwwwwww
*/


you just need to add "do you want to continue" functionality.
also check if the number is bigger than 2, as you did on your own code.

also, while you're posting your code, click the <> symbol on the right (under Format), and put your code within. please.
Last edited on
For your do you want to continue function, try this!
If you don't know what it means, please ask and I am sure many here can help you including me.
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
#include <iostream>
#include <string>
using namespace std;

int main(){
start:
      string restart;
	int n;
	char c;
	cout << "enter an integer and a character: ";
	cin >> n >> c;

	//print first line of chars. n times c
	for(int i = 0; i < n ; i++)	
		cout << c;
	
	cout << endl;
	
	//print diagonal lines
	int j;
	for(int i = n-1; i > 0; i--){ // how many lines
		for (j = i; j > 0; j--) //how many dots+c in a line
			cout << ".";
		cout << c << endl;	
	}

	//print the last line (same as first line)
	for(int i = 0; i < n ; i++)	
		cout << c;		

	cout << endl;
	cout << "Do you wish to continue? ";
	cin >> restart;
	if ( restart == "Yes" || restart == "yes" || restart == "y" || restart == "Y")
	{ goto start;}
	else
	system("PAUSE");
return 0;
}

/*
enter an integer and a character: 12 w
wwwwwwwwwwww
...........w
..........w
.........w
........w
.......w
......w
.....w
....w
...w
..w
.w
wwwwwwwwwwww
*/

p.s. you could probably change my string to a char and edit the code a little so that you can use a char variable. Your choice.
This is what I got, it has a continue (YAY!), may be wrong though.

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
#include<iostream>
using namespace std;

int main() {
	char answer;
	cout << "Does thou wants to do this? (y or n)" << endl;

	while (true) {
		if (cin >> answer) {
			if (answer == 'y') {

	int norows = 0;
	char fillin;
	
	cout << "Enter number of rows." << endl;
	cin >> norows;

	cout << "Enter character for fill in." << endl;
	cin >> fillin;

	for (int i = 0; i < norows; i++) {
		cout << fillin;}

	cout << endl;

	for (int i = 0; i < (norows - 2); i++){
		for (int k = 0; k < (norows - i - 2); k++){
			cout << " ";}
		cout << fillin;
		for (int g = 0; g < (i + 1); g++) {
			cout << " ";}
		cout << endl;}

	for (int i = 0; i < norows; i++) {
		cout << fillin;}

	cout << endl << "Dos thou want to continue? (y or n)" << endl;}

			else if (answer == 'n') {break;}}}

	return 0;}

Topic archived. No new replies allowed.