1
下面的代碼打印出用戶輸入的整數框。我需要讓它變成空心的,只顯示框的第一行和最後一行的全長。像寬度= 5高度= 4如何在for循環中創建異常?
示例輸出:
00000
0 0
0 0
00000
來源:
int main()
{
int height;
int width;
int count;
int hcount;
string character;
cout << "input width" << endl;
cin >> width;
cout << "input height" << endl;
cin >> height;
cout << "input character" << endl;
cin >> character;
for (hcount = 0; hcount < height; hcount++)
{
for (count = 0 ; count < width; count++)
cout << character;
cout << endl;
}
}
我不知道如何改變循環條件爲寬度,使其工作。
打印'character'然後打印'寬度 - 2'空間然後打印另一'character'。 –