craps game please help me

Write your question here.
create a craps game 3 files ( main cpp. dice.cpp dice.h files) You will need to create a Dice or Die class to play. Use "rand() % 6 + 1" to produce a random number between 1 and 6. Create two instances (objects) of the Die/Dice class to conduct each roll and call a function called roll to produce two int between 1 and 6 and add the results together for a roll.

Craps has two phases: the first roll and the next rolls.

If the first roll is 7 or 11 the players wins. Print out (cout) you win!
If the first roll is 2 or 12 the player loses. Print out you lose!
Any other roll becomes the target (point) and the game continues.

On consecutive rolls:
If the roll = the target (points) the player wins. Print out you win!
If the roll = 7 the player loses. Print out you lose.

Keeps rolling until the game is over (player wins or loses).
um... so whats the issue?
I want to help me to do this task.
you should start by giving it a shot. no one here will just write all of your code.
#include <iostream>
using namespace std;

int main()
{ for (int i = 0; i < 1000; i++)
{ int die1, die2, roll1, roll2, point,;
die1 = 1 + rand() % 6;
die2 = 1 + rand() % 6;
point = die1 + die2;
cout << "You rolled: " << point << endl;
if( point == 7 || point == 11 )
{cout << "You win! Would you like to play again? "; }
else if( point == 2 || point == 3 || point == 12 )
{cout >> "Sorry you lose. Do you want to play agin? ";
}
return 0;
}
is this correct and answer all required in question?
No
create a craps game 3 files ( main cpp. dice.cpp dice.h files)

I think you need to write a class in another file called dice.h
closed account (1CfG1hU5)
your code from a quick glance looks right functional to me john.

the if statements work well.
so please guys help me.

I'm beginner I don't know to do that.

please
You're not following the instructions directing you to create a class. You need to write a class called "die" which has a method called "roll". That class should be in its own file with its own header file. Then create a main file where you include the "die" class so you can use it to instantiate two dies that will be used in the craps game itself.

You also need to know the rules of craps. If you don't win or crap out on your roll you have to keep going and try and hit your target number. See here: http://en.wikipedia.org/wiki/Craps

Write your die class first so you can test it on its own before moving on to the main program logic that implements the rules of craps.
I try to write the code as the instruction, but I got errors:
1>c:\users\naif\documents\visual studio 2010\projects\craps_game\craps_game\main.cpp(11): error C2039: 'crap' : is not a member of 'Craps' 1> c:\users\naif\documents\visual studio 2010\projects\craps_game\craps_game\craps.h(6) : see declaration of 'Craps'

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <ctime>
#include <limits>
using namespace std;
class Craps
{

public:
   Craps()
   {
  
   }
   void crap(Craps &obj)
   {
       int die1=0, die2 = 0,roll1=0;
       char repeat = 'y';
       cout << "Welcome. The game is about to begin." << endl;
       while (repeat == 'y' || repeat == 'Y') //still needs ' '
       {
           //cin.ignore();
           die1 = rand() % 6 + 1;
           die2 = rand() % 6 + 1; //dont need brackets around rand()
           roll1 = die1 + die2;
          
           cout << "Your roll is: " << die1 << " + " << die2 << " = " << roll1 << endl;
           if (roll1 == 7 || roll1 == 11)
           {
               cout << "You win!"<<endl<< "Would you like to play again? [Y/N]:" << std::endl;
               //cin.ignore();
               cin >> repeat;
           }
           else if (roll1 == 2 || roll1 == 12)
           {
               cout << "Sorry, you lose!"<<endl<<" Would you like to play again? {Y/N]:" <<endl;
               //cin.ignore();
               cin >> repeat;
           }
           else
           {
               cout << "Sorry, you nor lose! niether win ! "<<endl<<" Would you like to play again? {Y/N]:" <<endl;
               //cin.ignore();
               cin >> repeat;
           }
       }
   }

};
int main()
{
   Craps obj;
   obj.crap(obj); //first instance

   Craps obj1;
   obj1.crap(obj1); //second instance
   return 0;
}


so please help me
please help, when I tried to run this code I got this problem

error C2039: 'crap' : is not a member of 'Craps'

on this code line:

obj.crap(obj);

obj1.crap(obj1);
I get no errors when I compile the above code with VS2010.

You've created a class to represent the game, but you're still not following the instructions to create a class to represent a die.

You also not modeling the game of craps correctly. If the first roll is not 1,7,2 or 12, the game is not over. See the instructions regarding consecutive rolls.
The instructions are your program! Just take each part of the instructions and restate them using the C++ statements:

Create a Dice or Die class to play.

In the class you created, include a value and a function "roll," using "rand() % 6 + 1" to set the class's value to a random number between 1 and 6

In main():
Create two instances (objects) of the Die/Dice class to conduct each roll

For each play of the game, do the following:

Starting out each game there is no point to compare:
Starting out each game you will continue to throw dice until you either win or lose:

//This starts the still playing loop:

Call the "roll" function in each object (die) you created, to set the value of each die to a random number;

add the value from each object to get your initial roll value.

//Craps has two phases: the first roll and the next rolls.

Phase 1 - if there is no point established:

If the first roll is 7 or 11
The player wins.
Print out (cout) you win!
The game ends.

If the first roll is 2 or 12
The player loses.
Print out you lose!
The game ends
Any other roll becomes the target (point)
The game continues.

Phase 2 - else the point has been set -- you didn't win or lose on the first roll, so do this until you either win or lose:

If the roll = the target (points)
The player wins.
Print out you win!
The game ends.
If the roll = 7
The player loses.
Print out you lose.
The game ends.

if you won or lost,
Repeat from the beginning of the game,
otherwise
Go back to the beginning of the "still playing" loop and roll again.
Last edited on
Topic archived. No new replies allowed.