c++ - 跳过for循环,为什么?

标签 c++ for-loop

我有一个作业,其中我必须用 C++ 创建一个控制台程序,以给定的样式绘制六边形。我遇到的问题是;我的 For 循环从未进入过,我也不知道为什么。这是我遇到问题的代码片段。

    void display()
{
    int counter=0;//var that keeps track of the layer that is being drawn
    for(int i=0;i>=size;i++)//spaces before first layer of hexagon
    {
        cout<<" ";
    }
    for (int k=0; k>size;k++)//top layer of hexagon
    {
        cout<<"_";
    }
    cout<<endl;//ends the first layer
    for (counter; counter>=size-1;counter++)//outer loop for the top half that controls the size
    {
        for( int j=0;j>(size-counter);j++)//adds spaces before the shape
        {
            cout<<" ";
        }
        cout<<"/";
        for( int p=0; p>(size+(counter*2));p++)//loop for the hexagon fill
        {
            cout<<fill;
        }
        cout<<"\\"<<endl;
    }
    for(counter;counter==0;counter--);  //loop for bottom half of the hexagon
    {
        for( int j=0;j>(size-counter);j++)//adds spaces before the shape
        {
            cout<<" ";
        }
        cout<<"\\";
        for( int p=0; p>(size+(counter*2));p++)//loop for the hexagon fill
        {
            cout<<fill;
        }
        cout<<"/"<<endl;
    }
    cout<<"\\";
    for(int r=0; r>=size;r++){cout<<"_";}
    cout<<"/"<<endl;

}

“大小”和“填充”是在我的 main() 期间在程序中较早选择的 我可能遗漏了一些非常简单的东西,但我已经为此苦苦挣扎了一段时间。任何帮助将不胜感激!

最佳答案

您的循环使用 >并从 0 开始。您似乎想要 <反而。例如

for(int i=0;i<size;i++)//spaces before first layer of hexagon
{
    cout<<" ";
}

关于c++ - 跳过for循环,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13235841/

相关文章:

java - 自定义对象的ArrayList

c++ - 从字符串中的整数进行加法运算

c++ - 程序入口点 SHGetKnownFolderPath shell32 未找到

c++ - 由于 if 语句 c++11 而避免重复代码的不便

c++ - 实现是否应该防止逗号重载?

algorithm - 循环算法设计

Python 迷你王国 : list childnode attributes per parent tag

batch-file - 使用 for 命令按字母顺序处理文件

c++ - C++用仅两个零替换数组中的偶数个零

c++ - 我是否应该在我的头文件中包含 <stdio.h>,这样我就可以声明一个接受 FILE* 的函数?