Hey guys, I'm just doing this code to see if it works where the user inputs a name and it outputs a menu where different options can be chosen.

For example, if the user press 1 the outputs of the name is reversed, if 2 is pressed the name is vertically forward slash, if 3 is pressed the name is vertically reversed backward slash, and if the user press 4, the name appears in a form of a triangle:


Here is part of my code but I don't know what is wrong with CASE 3, backward slash. Thank you in advance for any help!

int main(){

	string nm;
	cout<<"Hello! Please type only your first name: "<<endl;
	cin>>nm;

	int opt = 0;

	while (opt != 5){
		cout<<"Choose from the following options!\n"
		"if you want your name to be displayed...\n"
		"Reversed.......... press 1,\n"
		"Vertically-forward slash.......... press 2,\n"
		"Vertically reversed-backward slash.......... press 3,\n"
		"In form of triangle.......... press 4,\n"
		"Exit the program.......... press 5.\n";
		cin>>opt;

		int s = 0; //variables declared for case 2
		int s1 = 0;

		int s2 = 1; //variables declared for case 3
		int s3 = 1;


	
		switch (opt){
			
			case 1:
				revnm(nm);
				cout<<endl;
				break;

			case 2:
				fwd_slah(nm);
				for(int i=0; i<nm.size(); i++){
					for(int k=0; k<s; k++)
						cout<<" ";

					cout<<nm.substr(s1,1);
					cout<<endl;
					s++;
					s1++;

				cout<<endl;
				}
				break;

			case 3:
				bwd_slah(nm);
				for(int i=0; i<nm.size(); i++){
					for(int k=0; k<s2; k++)
						cout<<"";

					cout<<nm.substr(s3,0);
					cout<<endl;
					s2--;
					s3--;

				cout<<endl;
				}
				break;

Something like this? I can't tell without knowing what your functions are doing:

for (int i = 0;i<mystring.length();i++)
	{	
		for(int j=0;j<i;j++)
		        cout <<" ";
		
		cout<<mystring.substr(mystring.length()-1-i,1)<<endl;		
	}

But what exactly is that trying to do?
I guess to make the name appears backward slash is the same as the forward slash one but with a few differences, there is where I get lost!

That's for the backslash. You can modify as to whether or not you want the name backwards or not. It seemed like you had the forward slash down.
If you are confused write it out!! write down what array character you need when and try to work that into indicies as you move along the for loops.

Oh I see, yeah, actually it worked perfectly, thanks!
Now I need to focus on how to code the last one to make it look like a triangle!
:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.