C++ programming create a craps game 3 files ( main cpp. dice.cpp dice.h files) Y
ID: 3564257 • Letter: C
Question
C++ programming
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).
Explanation / Answer
Your correct anwer is here plz rate bro if you have any issue you can ask plz rate
#include <iostream>
#include <ctime>
#include <limits>
using namespace std;
//"dice.h"
class Craps
{
private:
int die1, die2,roll1;
public:
Craps();
void game(Craps &);
};
//Dice.cpp
//#include <iostream>
//#include <ctime>
//#include <limits>
//#include "dice.h"
//using namespace std;
Craps::Craps()
{
die1=0;
die2 = 0;
roll1=0;
}
void Craps::game(Craps &obj)
{
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;
}
}
}
//main.cpp
int main()
{
Craps blue;
blue.game(blue); //first instance
Craps red;
red.game(red); //second instance
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.