![]() |
|
#1
|
|||
|
|||
need help with loopingHello everyone..Infact i am developing a small game in C++.For now, i have to write codes such that there is a minimum of 2 players and maximum of 4 players.
Then, each player must select their color from values Red Blue Yellow and Green. The way i have written my code is too lengthy Im sure there is another way to do it with looping..But i dont know how..Can someone help me? This is what i have done till now.. CPP / C++ / C Code:
as you can see it is tooo lengthy..it works perfectly..But i have to remove these repetitions..Can anyone help me please? Last edited by admin II : 02-Apr-2008 at 04:28.
Reason: Changed [CODE] to [CPP]
|
|
#2
|
||||
|
||||
Re: need help with loopingThere are a couple of things wrong with your code that I'm assuming are due too you typing to fast, since you said it compiles. It looks like you've got some nested switch statements you want to get rid of. Is that correct? Can you give us some more details. There are a million different ways to get rid of those switch statments. Here is something to get you started:
CPP / C++ / C Code:
__________________
"To argue with a person who has renounced the use of reason is like administering medicine to the dead." -Thomas Paine www.sullivan-county.com/deism.htm |
|
#3
|
|||
|
|||
Re: need help with loopinghere is the code:
its a bit too lengthy that is why i didnt post it CPP / C++ / C Code:
as you can see i have written code when num_players is 2 that is code for player 1 and player 2.. when the num_players is 3, i rewrite these codes and then include code for player 3 and same when num_players is 4.. i have just posted code when num_players is 2..hope i have been able to explain what i meant to say... Last edited by admin II : 02-Apr-2008 at 04:29.
Reason: Changed [CODE] to [CPP]
|
|
#4
|
||||
|
||||
Re: need help with loopingYeah, I think I got what your asking. Did you read all of my post? Does my code make sense? You could also use functions and pointers. Something like this:
CPP / C++ / C Code:
__________________
"To argue with a person who has renounced the use of reason is like administering medicine to the dead." -Thomas Paine www.sullivan-county.com/deism.htm |
|
#5
|
|||
|
|||
Re: need help with loopingthanks...that was of great help..But is there a way without using pointers??pointers are confusing to me...
|
|
#6
|
||||
|
||||
Re: need help with loopingMy first example is without pointers. It's a good idea to get used to working with pointers. They're the bread and butter of c++. This page has a pretty good introduction to pointers. On this one you can get into the nitty gritty (how pointers operate on memory, how memory is stored, etc). This is also a good page on pointers. Anyway, give my suggestions a try and if you run into any problems, post them in this thread and I'll help you out.
__________________
"To argue with a person who has renounced the use of reason is like administering medicine to the dead." -Thomas Paine www.sullivan-county.com/deism.htm |
|
#7
|
|||
|
|||
Re: need help with loopingThanks..I have tried your example without pointers and it worked!!
i have another question: for instance if i have: Roll dice Display result if condition A is true.....line 1 { if number on dice is 6 {move pawn to position 0 Decrement pawns in base Roll dice again Display result Then perform line again } } how do i do this with looping? |
|
#8
|
||||
|
||||
Re: need help with loopingYou're going to have to be more specific. Also give it shot and post the code that is giving you trouble. I'm willing to help you, but I won't write all your code for you. Don't forget to enclose your code in [c] and [ \c++] code tags. There is a little c++ button on the format tool bar when you submit a reply. Pressing that will add the code tags to your post. It makes your post much easier to read
__________________
"To argue with a person who has renounced the use of reason is like administering medicine to the dead." -Thomas Paine www.sullivan-county.com/deism.htm |
Recent GIDBlog
Flickr uploads of IA pictures by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Looping with enum | Spidy08 | C++ Forum | 5 | 02-Oct-2007 09:44 |
| Need help with Looping | Harryt123 | C Programming Language | 4 | 21-May-2006 14:45 |
| Sample looping (do/while) | Sabin044 | C++ Forum | 8 | 04-Feb-2006 11:39 |
| 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