SO我已经创建,创建一个正方形或长方形的框架,我试图得到它的正方形/长方形内输出恒星的程序,所以它是半满的,像这样的:C++创建一个半满的矩形
********
** * * *
* * * **
** * * *
********
这里是我到目前为止的代码:
void frameDisplay(int width, int height) {
cout <<"What should the width be?\n";
cin >> width;
cout <<"What should the height be?\n\n";
cin >> height;
if(width < 2){
cout <<"Width must be greater than two.\n";
cout <<"What should the width be? \n";
cin >> width;
}if(height < 2){
cout <<"Height must be greater than two.\n";
cout <<"What should the height be? \n";
cin >> height;
}
cout << string(width, '*') << endl;
for(int j = 0; j < height - 2; ++j)
cout << '*'<< string(width - 2, ' ')<< '*' << endl;
cout << string(width, '*') << endl;
}
int main(){
int width=0, height=0;
frameDisplay(width, height);
}
输出:
What should the width be?
5
What should the height be?
7
*****
* *
* *
* *
* *
* *
*****
而问题将是...? – SergeyA
你的输出是什么? – MASh
如何让我的代码输出上面的图片,而不是像我的代码创建一个框架 – SillyPenguin420