No idea on how to do this...

• 12-05-2007
Sembhi
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?
• 12-05-2007
brewbuck
Quote:

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?
• 12-05-2007
MacGyver
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.
• 12-05-2007
Sembhi
Quote:

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?
• 12-05-2007
MacGyver
Look at your if statement and when you add to the total.
• 12-05-2007
Sembhi
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.
• 12-05-2007
MacGyver
What value does total have when the program starts?
• 12-05-2007
MacGyver
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.
• 12-05-2007
Sembhi
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.

I'm starting on the one I had originally posted about.
• 12-05-2007
Sembhi
Quote:

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?

OK I get what you're saying but I'm not sure how to put that into code.
• 12-05-2007
TyPR124
Think about if you just wanted the output to be A1A2A3. You would want something that would repeat three times, and each time add 1 to the number after A. Which kind of loop could do that?

Then once you figure out the A's, you should be able to figure out the B's as well.
• 12-05-2007
Sembhi
Got it. Thank you.