0
我正在尝试使用用户输入的选项创建一个梯形。我知道我的代码可能不是最好的方式,但迄今为止它的工作原理!我的问题是我需要梯形的底部触摸输出窗口的左侧。我究竟做错了什么?使用用户输入的字符创建梯形。 (控制台应用程序)
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
int topw, height, width, rowCount = 0, temp;
char fill;
cout << "Please type in the top width: ";
cin >> topw;
cout << "Please type in the height: ";
cin >> height;
cout << "Please type in the character: ";
cin >> fill;
width = topw + (2 * (height - 1));
cout<<setw(width);
for(int i = 0; i < topw;i++)
{
cout << fill;
}
cout << endl;
rowCount++;
width--;
temp = topw + 1;
while(rowCount < height)
{
cout<<setw(width);
for(int i = 0; i <= temp; i++)
{
cout << fill;
}
cout << endl;
rowCount++;
width--;
temp = temp +2;
}
}
这是功课? – Xorlev 2010-03-04 06:39:59
“最好的梯形”是什么意思? – 2010-03-04 06:56:59