print name vertically,diagonally and horizontal

help i need a code that can print a name vertically,diagonally and horizontal at the same time

alejandro
l
e
j
a
n
d
r
o


sorry for the trouble but im a beginner
im hardly began over a month ago
Last edited on
Nested for-loop. Inside a condition that prints either a characted from name or space.
Here is some code to get you started. Get this to compile and run on your system and begin working through it in iterations to put in 1 requirement at a time.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <string>

int main()
{
    std::string myName("alejandro");

    for(int row = 0; row < myName.size(); row++)
    {
        std::cout << myName;
        std::cout << '\n';
    }

    return 0;
}

As it works now, there are as many "rows" as there are characters in the string. Here are the iterations I would try to get working, in order:
1. Make the whole name print on the first row (row 0) only.
2. On the other rows, make the appropriate character print once.
3. On the other rows, make the appropriate character print twice.
4. On the other rows, print the appropriate amount of spaces between the characters discussed in steps 2 and 3 to give the impression of a diagonal print.

By this I mean, get 1. to work. Then get 2. to work, etc.
Last edited on
maybe i didn't explain myself it has to print any name that you input not just alejandro
Then read an input into 'myName' instead of hard-coding it.
See example code here:
http://www.cplusplus.com/reference/string/string/getline/
so my teacher is asking to input a name so it has to print it vertically, horizontally and diagonally so far i have done vertically and horizontally but the only thing holding me back is how to print diagonally
@simonsays0704

Here's all three at once..

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

int main()
{
    std::string myName;
	std::cout <<"Enter the name you wish to be printed: : ";
	std::getline(std::cin,myName);
	std::cout << std::endl << std::endl << myName << std::endl;
//Above prints full name text 
    for(int row = 1; row < myName.size(); row++) // prints 2nd letter onward
    {
        std::cout << myName[row];// prints name[row] letter
		for(int x=1;x<row;x++)
		{
			std::cout << " "; // prints spaces up to where row is on name
		}
		std::cout << myName[row] << std::endl;
	}
    return 0;
}
Last edited on
thanks you saved my skin
Topic archived. No new replies allowed.