Bit
Bit

Reputation: 3

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. 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). To show how advanced I am, I have just started learning about the 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

output: aBBBBaBBBBaBBBBaBBBB

Upvotes: 0

Views: 35

Answers (1)

N1kla3
N1kla3

Reputation: 26

    #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;
    }

Upvotes: 1

Related Questions