# Thread: No idea on how to do this...

1. ## No idea on how to do this...

"Write a program that uses nested loops to produce the following output.
A1B1B2B3A2B1B2B3"

Any tips on where I should start?

2. Originally Posted by Sembhi
"Write a program that uses nested loops to produce the following output.
A1B1B2B3A2B1B2B3"

Any tips on where I should start?
The pattern looks like "A1 x A2 x A3 x..." Where "x" is "B1 B2 B3". So you have an outer loop counting through the "A"s and an inner loop counting through the "B"s. Does that help?

3. Code:
```#include <iostream>

int main()
{
/* Insert code here */
return 0;
}```
Start here.

Research loops if you need to. Look back at the output you need to spit out, and then try to figure out how you can use loops to do it. Once you figure it out, put it into code.

4. Originally Posted by brewbuck
The pattern looks like "A1 x A2 x A3 x..." Where "x" is "B1 B2 B3". So you have an outer loop counting through the "A"s and an inner loop counting through the "B"s. Does that help?
Yea that does.

Need help with another program real quick. I have to keep getting a number from the user until they enter 0. I also need to add up all the numbers they enter and display it. How do I do this?

Heres my code:

Code:
```#include <iostream>

int main()
{
int sum = 0;
int num;
int total;

do
{
cout << "Enter a number (Enter 0 to quit): ";
cin >> num;
if (num == 0)

{total = num;
total = total + num;
cout << total;
break;}

}
while (1);
return 0;
}```
When I enter 0 to end the program and display the sum...it comes up as 0. Help?

5. Look at your if statement and when you add to the total.

6. Still confused. This is what I have.

Code:
```	do
{
cout << "Enter a number (Enter 0 to quit): ";
cin >> num;

total = num;
total = total + num;

if (num == 0)

{
cout << total;
break;
}```
I don't understand why total showing up as 0.

7. What value does total have when the program starts?

8. You didn't do that in the code you posted, and you're overwriting the value of total with num, and then adding num to total. On the other hand, you do have a variable called sum, which is initialized to 0.

Step through the program logic very slowly. I think you may be trying to do a bunch of small edits, which are making the program very ridiculous. Just go over it and make sure everything is done in the proper order.

9. Yea I saw. Thanks for the help. Works fine now.

The reason I had sum = 0 was because the problem told me. Not sure why though. Oh well, that one is done.