HELP PLSSS...

anyone have a source code for a game program of rock,paper & scissors..
pls give me some..just a simple one, would use it in c++ programming..
it would be for our finals...
Many would consider it unethical to do another person's final for them, in its entirety.
Instead, why don't you show us what you've got, and we can give you pointers?
i just have a problem in how would paper win over rock,etc..
should i be using if else statement??
1
2
3
4
5
6
7
8
// pseudocode = yes

bool who_wins ( char yourchoice, char mychoice )
{
if ( yourchoice=='p' && mychoice=='r' ) return 1; // You won
if ( yourchoice=='p' && mychoice=='s' ) return 0; // I won
...
}

closed account (z05DSL3A)
__Hotaru,

What would you return for a draw?

__immortaL

There are three possible outcomes to the game (win, loose, or draw).

Your first test should see if it is a draw. Your second check, if needed, should be to see if you have won. As there are only three options (Rock, paper, and scissors) and each one of those has a single winning condition, so only three checks are needed to find a winning condition. Finally, if you have not drawn and if you have not won, then you have lost.

AS it is for your finals, I don’t want to give any code, but hope you can work out some structure from the above.

Last edited on
i have the source code, but i won't post it

i created an array
1
2
3
4
5
6
string choices[4] = {
                                   "",
                                   "Rock",
                                   "Paper",
                                   "Scissors"
                               };


then i subtracted yourchoice from mychoice
and if the result was 1 or -2, yourchoice won; if it was -1 or 2 mychoice would win
Topic archived. No new replies allowed.