我目前正在研究一個項目,提示用戶輸入他們想要用於他們的盒子的高度,寬度和字符。我必須使用for循環創建一個實心和空心的盒子。我創造了一個沒有問題的堅實的人,但是當談到空心人時,我遇到了一些問題。任何幫助表示讚賞。C++如何用用戶輸入創建一個空心框/矩形?
int main()
{
int height;
int width;
int i, j;
char ch;
cout << "Please enter your height: ";
cin >> height;
cout << "Please enter your width: ";
cin >> width;
cout << "Please enter your character: ";
cin >> ch;
for (i = 1; i <= height; i++)
{
for (j = 1; j <= width; j++)
cout << ch;
cout << endl;
}
cout << "Press any key to continue to the next shape." << endl;
_getch();
for (i = 1; i <= height; i++)
{
for (j = 1; j <= width; j++)
{
if (i == 1 || i == width -1 || j == 1 || j == height)
cout << ch;
else cout << " ";
}
cout << endl;
}
system("pause");
return 0;
}
「有些問題」是不是一個很好的問題陳述。請[編輯]您的問題以包含更具體的描述。 – Ajean