Nested loop

How would i output "A1B1B2B3A2B1B2B3" with nested loop?

 
  ik i should know how to do this and its driving me insane because i cant figure it out? please help
11232123? I don't see a clear pattern there unless it's some weird modulo stuff.
its A with 1 then B 3 time with 1-3 the A with 2 then B again with 1-3
the b with 1-3 is the inner loop i know that and the A with 1 and 2 every 3 times
i think??
I have it so i can get to A1B1B2B3 now i need A2B1B2B3

1
2
3
4
5
6
7
cout << letter << number;
		letter++;

		for (number = 1; number <= 3; number++)
		{
			cout << letter << number;
		}
I GOT IT:)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

using namespace std;

int main()
{
	int number = 1;//1-3
	int number2 = 1;//1-2

	for (number2 = 1; number2 <= 2; number2++)//number for A 1-2
	{
		cout << 'A' << number2;

		for (number = 1; number <= 3; number++)//number for B 1-3
		{
			cout << 'B' << number;
		}
	}
	cout << endl;
	return 0;
}
//A1B1B2B3A2B1B2B3
//Press any key to continue . . . 
You're missing your nested loop though :P

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Example program
#include <iostream>

int main()
{
    int iterations = 0;
    std::cout << "How many times would you like the sequence to repeat? ";
    std::cin >> iterations;
    
    //The loops start at 1 instead of 0 because it doesn't seem
    //logical to add one every time you loop just to output :P
    for(int i = 1; i <= iterations; ++i) //a1-aITERATIONS
    {
        std::cout << 'A' << i;
        for(int j = 1; j <= 3; ++j) //b1-b3
        {
            std::cout << 'B' << j;
        }
    }
    
    return 0;
}
How many times would you like the sequence to repeat? 10
A1B1B2B3A2B1B2B3A3B1B2B3A4B1B2B3A5B1B2B3A6B1B2B3A7B1B2B3A8B1B2B3A9B1B2B3A10B1B2B3 






:P See you just posted right before me with almost identical solution good job!
Last edited on
Theres a nested loop it has the 2 for loops. its only suppose to print that one sequence no repeatedly for the assignment.
If you look at the time stamps mine was posted 1 minute after yours :P so when I was typing it that one wasn't there and the first one didn't have a nested loop.
Topic archived. No new replies allowed.