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