I was given a task by my professor to create a pattern in c++ output using a string input by user.
The program should run in the following way:
Enter a string: ***
***
***
***
***
***
***************
***
***
***
***
***
Note : The input string from user can have any number of length or characters
Following are the restrictions for the program:
- No string literals or white spaces in cout statement allowed.
- Use of loops is also forbidden (This is the reason i am stuck ... i successfully created the above program but by using loops)
- No advanced concept of c++ are allowed (at college we just started with basic concepts of how the language works. so please keep this in mind while giving the answer)
I have tried multiple ways to create the above program but due to given restrictions i don't think its possible anymore, so that's why i came here to ask help from the community.
Here is my code below using loops:
string userInput;
int m = 1, n = 9;
cout<<"\nEnter a three character string: ";
cin>>userInput;
cout<<endl;
while (m <= 6)
{
if (m == 6)
{
cout<<userInput<<userInput<<userInput<<userInput<<userInput<<endl;
m = 1;
n = 13;
while (m <= 5)
{
cout<<setw(n)<<userInput<<endl;
m++;
n--;
}
return 0; //this will finish the execution of the program
}
cout<<setw(n)<<userInput<<endl;
n++;
m++;
}
The above program works if user enters 3 character string only
Help will be highly appreciated!
Sorry for my bad English, feel free to edit and correct it if you find any errors or mistakes