Reputation: 3
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
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