我能够制作一个上升的计数器但是下来呢?总的来说,我希望它如此:
1
12
123
1234
12345
12345
1234
123
12
1
上面的代码是我想要的最终结果。但我似乎无法让嵌套的for循环工作以便倒计时。
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int row, col;
int size;
int mych;
int printch = 1;
cout << "Size of Shapes (>0) ";
cin >> size;
while (size<0)
{
cout << "\nSize of Shapes (>0) ";
cin >> size;
}
cout << "Characters to use: ";
cin >> mych;
for(row = 1; row <= size; row++)
{
printch = mych;
cout << "\n" << setw(8);
for(col = 1; col <=row; col++)
{
cout << printch;
printch++;
}
}
for(row = size ; row <= size; row++)
{
printch = mych;
cout << "\n" << setw(8);
for(col = mych; col <=row; col++)
{
cout << printch;
printch++;
}
}
cout << "\n\n";
system ("pause");
return 0;
}
我对这个问题很难过。任何帮助将不胜感激!
答案 0 :(得分:2)
for(row = size ; row <= size; row++)
(即第二个外for
循环)
实际应该是:
for(row = size ; row >= 0; row--)
问题是,当你从大小开始时,你应该减少行而不是增加它,并在你达到0时结束。