简体   繁体   English

我在循环中的循环中遇到问题无法正常工作

[英]I'm having a problem in a loop in a loop not working properly

I just started learning c++ and I'm a total noob in this.我刚开始学习 c++,我完全是个菜鸟。 For homework I got a question "Make a program, that will show a massage like 'aBBBaBBBaBBB'. The amount of 'B' is connected with the number provided from the start. In front of the line of B's there has to be a letter 'a'" (translated from polish).对于作业,我有一个问题“制作一个程序,它将显示像'aBBBaBBBaBBB'这样的按摩。'B'的数量与从一开始提供的数字有关。在B的行前面必须有一个字母'a'"(翻译自波兰语)。 To show how advanced I am, I have just started learning about the function "for".为了显示我有多先进,我刚刚开始了解 function “for”。

#include <iostream>

using namespace std;

int main()
{
    int b, x;
    cin>> b;

   for(x=0; x<=b; x++)
   {
        for(x=1; x<=b; x++)
        {
            cout << "a";

            for(x=1; x<=b; x++)
            {
                cout << "B";
            }
        }
   }
return 0;
}

input: 4输入:4

output: aBBBBaBBBBaBBBBaBBBB output:aBBBBaBBBBaBBBBaBBBB

    #include <iostream>

    using namespace std;

    int main()
{

    int b;
    cin>> b;

    for(int x = 0; x < b; x++)
    {       
         cout << "a";

         for(int x = 0; x < b; x++)
         {
             cout << "B";
         }
    }
    return 0;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM