GIDForums  

Go Back   GIDForums > Computer Programming Forums > CPP / C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 10-Apr-2006, 00:48
fj8283888 fj8283888 is offline
Junior Member
 
Join Date: Apr 2004
Posts: 37
fj8283888 is on a distinguished road

Looping


Dear All:

I would like to show this as following with For loop
Numbers: 1,2,3,4,5 each line must be unique, for example (1,2) , (2,1) can not be show.


1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5


Thanks,

Li
  #2  
Old 10-Apr-2006, 02:22
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,234
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Looping


Loop INDEX1 from 1 to MAX-1
Loop INDEX2 from INDEX1+1 to MAX
__________________

Cow: You're a lawyer too?
Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase!
  #3  
Old 11-Apr-2006, 02:01
fj8283888 fj8283888 is offline
Junior Member
 
Join Date: Apr 2004
Posts: 37
fj8283888 is on a distinguished road

Re: Looping


In c++ coding, how could I write as for loop?

Thanks,
Li
  #4  
Old 11-Apr-2006, 09:33
TreyAU21's Avatar
TreyAU21 TreyAU21 is offline
Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 116
TreyAU21 has a spectacular aura aboutTreyAU21 has a spectacular aura about

Re: Looping


Here ya go:

CPP / C++ / C Code:
#include <iostream> 
#define MAX 5

    int main () { 
      int index1, index2;
      for(index1=1; index1<=MAX; index1++) {
         for(index2=index1+1; index2<=MAX; index2++) {
            std::cout << index1 << " " << index2 << "\n"; }
      }
      
      return 0; 
   } 
__________________
If practice makes perfect and nobody's perfect... why practice?

Homepage: http://www.treywhite.com
Blog: http://www.treywhite.com/blog.php
Web Design Company: http://www.ewebproductions.com
  #5  
Old 11-Apr-2006, 10:05
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,234
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Looping


Quote:
Originally Posted by TreyAU21
Here ya go:

CPP / C++ / C Code:
#include <stdio.h> 

#define MAX 5


    int main () { 
      int index1, index2;
      for(index1=1; index1<=MAX; index1++) {
         for(index2=index1+1; index2<=MAX; index2++) {
            printf("%d %d\n", index1, index2); }
      }
      
      return 0; 
   } 
Not only is this code wrong, here at GID Forums we try to help them find the answer, not give them the answer on a silver platter. I could have done what you did but wanted fj8283888 to learn how to do it himself.
__________________

Cow: You're a lawyer too?
Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase!
  #6  
Old 11-Apr-2006, 10:08
TreyAU21's Avatar
TreyAU21 TreyAU21 is offline
Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 116
TreyAU21 has a spectacular aura aboutTreyAU21 has a spectacular aura about

Re: Looping


Quote:
Originally Posted by WaltP
Not only is this code wrong, here at GID Forums we try to help them find the answer, not give them the answer on a silver platter. I could have done what you did but wanted fj8283888 to learn how to do it himself.

Chill! You handle things your way, and I'll handle things my way... and the code isn't wrong (I assume you are referring to the fact that it was written in C... which I changed at some point between when you clicked to respond and when you actually posted to C++). I believe that revealing an answer in this sort of an example is just as much of a benefit as letting the person come to the answer on their own. It's not like fj8283888 was asking how to code an iteratively-deepening a* tree or anything of that nature. We are talking about loops here... in their basic form. Just like reference books, the answer is often REVEALED and then explained. It's okay to do that on these forums as well.

I understand that you've been on these forums alot longer than I have... and you've probably been coding alot longer as well, but people have different ways of helping, and we don't all have to do it your way. You aren't the post police, so I don't have to do it your way, though I appreciate the way you handle situations... let me do it my way. That's it!
__________________
If practice makes perfect and nobody's perfect... why practice?

Homepage: http://www.treywhite.com
Blog: http://www.treywhite.com/blog.php
Web Design Company: http://www.ewebproductions.com
  #7  
Old 11-Apr-2006, 12:03
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,234
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: Looping


Quote:
Originally Posted by TreyAU21
Chill! You handle things your way, and I'll handle things my way... and the code isn't wrong (I assume you are referring to the fact that it was written in C... which I changed at some point between when you clicked to respond and when you actually posted to C++).
I am chilled. I'm simply pointing out that giving the answer does not aid in learning as well as giving pointers.

And the code is wrong. Your first loop should go from
index1 < MAX not <= MAX

Quote:
Originally Posted by TreyAU21
I believe that revealing an answer in this sort of an example is just as much of a benefit as letting the person come to the answer on their own. It's not like fj8283888 was asking how to code an iteratively-deepening a* tree or anything of that nature. We are talking about loops here... in their basic form. Just like reference books, the answer is often REVEALED and then explained. It's okay to do that on these forums as well.
If you believe this, then you forgot to explain. I disagree in principal, though. If this is a homework assignment, you have in fact given the answer -- the OP did nothing but post a question and have his homework done for him. This is why I believe we should not give code, but pointers.

And at the OP's level of experience, this problem was just as difficult as "how to code an iteratively-deepening a* tree" to a more experienced programmer. Is there an experience level when types of help are permitted and not? (Rhetorical question)


Quote:
Originally Posted by TreyAU21
I understand that you've been on these forums alot longer than I have... and you've probably been coding alot longer as well, but people have different ways of helping...
All true. But maybe my experience and longevity has some merit.


Quote:
Originally Posted by TreyAU21
You aren't the post police, so I don't have to do it your way, though I appreciate the way you handle situations... let me do it my way. That's it!
Are you sure I'm not? You've only been here a month... sorry, couldn't resist

Actually, no I'm not, and no you don't. But my post IMO is wasted because of the code. I would prefer not to waste my time helping someone just to have the next poster hand them the code. That's all I mean. My post no longer has value, and the OP now has working code. Possibly nothing learned.

Of course you are free to disagree with me. Differing perspectives are usually useful. I'm simply stating my opinion from of my experience. You may ignore my position if you wish, or try to understand it and accept or reject it. Your choice.

Yes, only my opinion. 'nuf said.
__________________

Cow: You're a lawyer too?
Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase!
  #8  
Old 11-Apr-2006, 13:45
TreyAU21's Avatar
TreyAU21 TreyAU21 is offline
Member
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 116
TreyAU21 has a spectacular aura aboutTreyAU21 has a spectacular aura about

Re: Looping


Quote:
Originally Posted by WaltP
I am chilled. I'm simply pointing out that giving the answer does not aid in learning as well as giving pointers.

And the code is wrong. Your first loop should go from
index1 < MAX not <= MAX

Either way works... in my design the conditional parameter for the second for loop is (index1+1) <= MAX... so in the case that index1 = MAX, index1+1 will be > MAX, so the inside of the second loop won't be reached.

Quote:
Originally Posted by WaltP
If you believe this, then you forgot to explain. I disagree in principal, though. If this is a homework assignment, you have in fact given the answer -- the OP did nothing but post a question and have his homework done for him. This is why I believe we should not give code, but pointers.

Understood... but you had already explained what needed to be done... the OP still sounded confused, so I threw the code out there

Quote:
Originally Posted by WaltP
And at the OP's level of experience, this problem was just as difficult as "how to code an iteratively-deepening a* tree" to a more experienced programmer. Is there an experience level when types of help are permitted and not? (Rhetorical question)



All true. But maybe my experience and longevity has some merit.



Are you sure I'm not? You've only been here a month... sorry, couldn't resist

Actually, no I'm not, and no you don't. But my post IMO is wasted because of the code. I would prefer not to waste my time helping someone just to have the next poster hand them the code. That's all I mean. My post no longer has value, and the OP now has working code. Possibly nothing learned.

Of course you are free to disagree with me. Differing perspectives are usually useful. I'm simply stating my opinion from of my experience. You may ignore my position if you wish, or try to understand it and accept or reject it. Your choice.

Yes, only my opinion. 'nuf said.

This is probably where I messed up. You had already taken the effort to help this person, so I should have not intervened. Had I been the first response to this post and given the solution with an explanation, it would have been different. However, since you were the first to respond... and you were obviously using your method, I shouldn't have posted a solution like I did, but maybe another hint to get the answer out of them.

Didn't mean to start any drama... I just didn't like getting attacked... particularly when I was trying to help as well. Perhaps (being more of a newcomer to these forums), I am a little more naive to the amount of people who only come on here for quick answers (rather than to learn)... though I'm pretty good at spotting them. Let's just say that if you're helping someone, I'll make sure not to serve up the answer to them on the metaphorical silver platter. Time for some dancing bananas....
__________________
If practice makes perfect and nobody's perfect... why practice?

Homepage: http://www.treywhite.com
Blog: http://www.treywhite.com/blog.php
Web Design Company: http://www.ewebproductions.com
  #9  
Old 11-Apr-2006, 21:12
fj8283888 fj8283888 is offline
Junior Member
 
Join Date: Apr 2004
Posts: 37
fj8283888 is on a distinguished road

Re: Looping


Guys, Thank you so much for giving me the solution.
Be happy guys. I know you guys are helping me lot
 
 

Recent GIDBlogToyota - 2008 July Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
my 1st simple program, 3 slight problems. skizer CPP / C++ Forum 11 07-Feb-2006 15:31
Sample looping (do/while) Sabin044 CPP / C++ Forum 8 04-Feb-2006 11:39
Problem with looping. rina C Programming Language 2 04-Oct-2005 06:37
ask looping likeit C Programming Language 4 26-Jul-2005 19:49
for looping prob Rosmayati C Programming Language 1 30-Jun-2004 11:39

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:39.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.