我的教授给我分配了一个任务,即使用用户输入的字符串创建C++输出的模式。
程序应按以下方式运行:
Enter a string: ***
***
***
***
***
***
***************
***
***
***
***
***
注意:用户输入的字符串的长度和字符数量都可以任意
以下是程序的限制:
- cout 语句中不允许有字符串常量或空格。
- 也禁止使用循环(这就是我被卡住的原因……我成功地创建了上面的程序,但是使用了循环)。
- 不允许使用C++的高级概念(在学校里,我们只学习了语言如何工作的基本概念,请在回答时牢记这一点)。
我尝试了多种方法来创建上述程序,但由于给定的限制,我现在认为不可能了,所以我来到这里向社区求助。
以下是我使用循环的代码:
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++;
}
以上程序仅适用于用户输入三个字符的字符串
非常感谢您的帮助!
对不起,我的英语不好,如果您发现任何错误或错误,请随意编辑和更正