Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm having a problem of understanding the logic of getting the following code to work the way I want it to in the beginning comment block:
/*
This project is to display
a set of numbers in the
following manner:123456789
12345678
1234567
123456
12345
1234
123
12
1*/
#include
int main()
{
// declare variables
int count;
int num;/*
make two for loops;
the outer loop is
to count and display
the rows for the inner
loop calculations
*/for (count = 1; count = 9; count++) // start of outer loop
{
cout endl;for (num = 1; num = 9; num++) // start of inner loop
cout num ""; // end of inner loop
} // end of outer counter loop
cout endl endl;return 0;
} // end of main

I'm guessing that you put signs where appropriate and the site stripped them. It does that. So, assuming that you used = in the test of the for loops and had the appropriate symbols in the 'cout' statments:
One problem is that you need the test in the inner loop to change according to the value of 'count' from the outer loop.for (num = 1; num = count; ++num)
I think that the second problem will become obvious when you implement the above change.
Post back if you have more questions. Also, please let us now when you get it working.

*&$#*&$@#$
I'm guessing that you put < and > signs where appropriate and the site stripped them. It does that. So, assuming that you used <= in the test of the for loops and had the appropriate symbols in the 'cout' statments:
One problem is that you need the test in the inner loop to change according to the value of 'count' from the outer loop.
for (num = 1; num <= count; ++num)
I think that the second problem will become obvious when you implement the above change.
Post back if you have more questions. Also, please let us now when you get it working.

To get the lt and gt signs to display, I do the following:
- when typing the original version of my post, I type 'lt' or 'gt' where I want a symbol.
- when you press the Submit button, you are taken to a confirmation page. On this page, I put a & in front of the 'lt' and 'gt'.
- my problem above was that I told the confirmation page to redisplay so that I could see the symbols. But when I pressed Submit, they were stripped. So remember, if you see the symbol on the confirmation page, you won't see it in the posted version. You should see the code "& lt" or "& gt" in the conf page.

hi~ it looks like using 9 will send you out
of the array bounds? i'm thinking 8 is a
better call.
right?

Hi. There is no need for an array variable in this case. However, if it is required in your assignment you should implement one. But I did not see any sort of specifications for it in your instructions. I can help you a little with your conditions and so forth.
I will give you a little hint with the counter variables in your for loops. Your 'count' variable should be initialized to 9 and decremented. Your 'num' variable should be initialized to 1 and incremented. Also be sure to make adjustments to your condition statements which compares 'count' and 'num' so you dont run into an infinite loop or worse.
Also you should make sure that adjustments are made to BOTH of your for loops. This way, it will produce the output the way you desire in the example provided in your code. I have already wrote the code and ran it, so if you are in extremely dire need then post back a comment. I will be glad to give you little snippets, but not the entire assignment.
I swore an oath not to do assignments for passer-byers in this forum. But I and the rest of the regulars here can provide sufficient help to get you on your way. I hope this helps you.
- Rolos

ahh. i see. i don't know where i got that
from? i worked it out with an array, and
now, i've worked it without, the for loops
do all of the work without the array, so i
guess that makes more sense. lol.

Haha you're right. I mean you could do it with an array, but I mean like you had said, it does make more sense to not use an array. It would be good practice if the objective is to implement arrays. But since you don't have to store the data, why use it right?
Anyhow, good luck with your assignment. If you need more help then just post back here.
- Rolos

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |