i am required to do this :

You will write the C++ program for a simple game playing system, which plays against a user. Let’s call the program P and the user U. P and U are in a magical world, in which a dragon can appear.
P and U both know that they are being watched by a troll. P and U know that the troll will give them coins depending on their joint behavior when the dragon appears. If they both do nothing, the troll will think they are nice, animal lovers and will give them each 10 gold coins. If they both draw their swords on the dragon, the troll will think they are stressed out and over-reacting, and give them 5 coin each. However, if the P draws its sword and the U does nothing, the troll will think that the P is very brave and that U is a coward, and give P 20 coins, and U nothing. Similarly, if U draws its sword and P does nothing, then the U will seem brave and get 20 coins, and P will get nothing.
A game is defined by one appearance of the dragon, a decision by your program, and a decision by the user. Coins are given to each player (your program and the user) according to the table above. Your program will control this game, play the part of the P, and also keep track of the number of coins it collects over repeated games. Your program wants to maximize the number of coins it gets over repeated games.
Your program will follow a particular strategy. For the first game, you can have it do whatever you want: nothing or draw its sword. But after that, your program will make its next decision depending on the joint outcome of the game just played. When both the user and program act peace loving (do nothing), both get 10 coins each. This is a good
reward and so your program will decide to repeat its decision to do nothing in the next game. However, an even bigger reward occurs when your program decided to draw its sword (20 coins) and the user decided to act peace loving (did nothing and got 0 coins)). When this situation occurs, your program will repeat its decision to draw its sword on the very next game.
Your program will switch its decision in the other two cases with worse outcomes, from its viewpoint: when it did nothing but the user drew sword (P gets 0 and U gets 20), and when both P and U drew swords (5 coin each). These are not very good outcomes from the P’s viewpoint, so it switches its decision on the next game.
Your program should produce behavior like this:
How many games do you want to play? 3 {user enters 3}
Game 1.
I’ve made my decision. What is your decision? : S {user enters S for sword}
My decision: sword. Your decision: sword
I have 5 coins. You have 5 coins.
Game 2.
I’ve made my decision. What is your decision? : N {user enters N for nothing}
My decision: nothing. Your decision: nothing
I have 15 coins. You have 15 coins. {updates the total coins}
Game 3
I made my decision. What is your decision? : S
My decision: nothing. Your decision: sword
I have 15 coins. You have 35 coins.
End of games.
Obviously, to be fair, your program must set its decision before asking the user what his or her decision is.

I have worked on this programming for a while ,
but always have problems here and there ,~
so if anyone can help me with it ?
Thanks a lot ~

You will write the C++ program

notice this line right here, the first line of your assignment. now, lets meditate on it for a moment... what do you imagine this means?

I have worked on this programming for a while ,
but always have problems here and there ,~

yeah, really? here and there? ... you know, i don't think i believe you.

.

Dude just post the code that you have worked on and are having mistakes, We can then help you, Daniweb isnt a homework service. You will need to show some effort.

//This is a game that demonstrates the Prisoner's dillemma.
#include <iostream.h>
#include <stdlib.h>

int main()
{int games;
char CompAction;
char useraction;
int CompCoins;
int UserCoins;
int number;

CompAction='N';
CompCoins=0;
UserCoins=0;
number=1;

cout<<"Please specify the number of games you want to play: ";
cin>>games;

while (games>0)
{ games=games-1;
  cout<<"Game "<<number++<<endl;
  cout<<"I have made my decision.  What is your decision (S/N)?";
  cin>>useraction;
   if ((CompAction=='S')&&(useraction=='S'))
    {
     CompAction='N';                                         
     CompCoins=CompCoins+5;
     UserCoins=UserCoins+5;

     cout<<"My decision:sword.  Your decision:sword."<<endl;
     cout<<"I have "<<CompCoins<<" coins. You have "<<UserCoins<<" coins."<<endl;
    }

       else if ((CompAction=='S')&&(useraction=='N'))
       {
       CompAction='S';
       CompCoins=CompCoins+20;
   
       cout<<"My decision:sword.  Your decision:nothing."<<endl;
       cout<<"I have "<<CompCoins<<" coins. You have "<<UserCoins<<" coins."<<endl;
       }

                else if ((CompAction=='N')&&(useraction=='S'))
                {
                CompAction='S';
                UserCoins=UserCoins+20;

                cout<<"My decision:nothing.  Your decision:sword."<<endl;
                cout<<"I have "<<CompCoins<<" coins. You have "<<UserCoins<<" coins."<<endl;
                }
   
    else 
    {
    CompAction='N';
    UserCoins=UserCoins+10;
    CompCoins=CompCoins+10;
   
    cout<<"My decision:nothing.  Your decision:nothing."<<endl;
    cout<<"I have "<<CompCoins<<" coins.  You have "<<UserCoins<<" coins."<<endl;
    }

}  cout<<"End of games"<<endl;// End of while statement


      system("PAUSE");
      return 0;
}

here z what i ve done ~ i dont know if it is ok or not ~ if you can fix the problems that i have ~ that would be helpful ~ thanks a lot

So what problems do you have?
Does it compile?
If yes: What output are you getting, and what ouput are you expecting?

Next time you post code, please use [code=cpp] //your code here

[/code]
code tags

And what's wrong with you keyboard? Where I come from, we use a . at the end of a sentence not a ~

Well, this assignment is a classic example of game theory. It might help to read up on the prisoner's dilemma to get a better idea of what the assignment is asking for.

It might help to read up on the prisoner's dilemma to get a better idea of what the assignment is asking for.

I know what the assigment is, the OP explained in post 1.

He posted code and I asked him what was wrong with it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.