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
#include <iostream>
usingnamespace 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.
#include <iostream>
#include <string>
usingnamespace 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.