"Write a program that uses nested loops to produce the following output.
A1B1B2B3A2B1B2B3"
Any tips on where I should start?
"Write a program that uses nested loops to produce the following output.
A1B1B2B3A2B1B2B3"
Any tips on where I should start?
Start here.Code:#include <iostream> int main() { /* Insert code here */ return 0; }
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.
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:
When I enter 0 to end the program and display the sum...it comes up as 0. Help?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; }
Look at your if statement and when you add to the total.
Still confused. This is what I have.
I don't understand why total showing up as 0.Code:do { cout << "Enter a number (Enter 0 to quit): "; cin >> num; total = num; total = total + num; if (num == 0) { cout << total; break; }
What value does total have when the program starts?
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.
Last edited by MacGyver; 12-05-2007 at 07:15 PM.
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.
Last edited by Sembhi; 12-05-2007 at 07:25 PM.
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.
Got it. Thank you.