Trying to make a Craps game for my assigment
Sep 26, 2018 at 5:58pm UTC
I'm trying to make the program generate random numbers but i'M stuck with how I would create a loop. I'm just a bit confused on how I would create a loop so that it would output with what my teacher wants.
Player rolled: 6 + 4 = 10
The point is 10
Player rolled: 3 + 3 = 6
Player rolled: 6 + 3 = 9
Player rolled: 3 + 1 = 4
Player rolled: 3 + 4 = 7
You seven'd out and lost!
Player rolled: 3 + 1 = 4
The point is 4
Player rolled: 5 + 1 = 6
Player rolled: 4 + 4 = 8
Player rolled: 6 + 6 = 12
Player rolled: 4 + 4 = 8
Player rolled: 2 + 1 = 3
Player rolled: 5 + 1 = 6
Player rolled: 2 + 4 = 6
Player rolled: 3 + 5 = 8
Player rolled: 5 + 3 = 8
Player rolled: 2 + 1 = 3
Player rolled: 2 + 2 = 4
You rolled your point! You won!
This is what I got so far.
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 57 58 59 60
#include <iostream>
#include <ctime>
#include <time.h>
#include <cstdlib>
using namespace std;
int main()
{
int die1;
int die2;
int rollingDice;
int rollingDice2;
const int SnakeEyes = 1 + 1;
const int Boxcars = 6 + 6;
const int Craps = 2 or 3 or 12;
srand(22);
die1 = rand() % 6 + 1;
die2 = rand() % 6 + 1;
rollingDice = die1 + die2;
rollingDice2 = die1 + die2;
cout << "Player rolled: " << die1 << " + " << die2 << " = " << rollingDice << endl << endl;
if (rollingDice == 7 or rollingDice == 11)
{
cout << "You won!" << endl;
}
else if (rollingDice == 2 or rollingDice == 3 or rollingDice == 12)
{
cout << "Craps! You lost!" << endl;
}
if ( rollingDice == 4 or rollingDice == 5 or rollingDice == 6 or rollingDice == 8 or rollingDice == 9 or rollingDice == 10)
{
cout << "The Point is " << rollingDice << endl << endl;
}
cout << "Player rolled: " << die1 << " + " << die2 << " = " << rollingDice2 << endl << endl;
while (rollingDice2 != rollingDice && rollingDice2 != 7);
if (rollingDice2 == rollingDice)
{
cout << "You rolled your point! You won!" << endl;
}
else if (rollingDice2 == 7)
{
cout << "You seven'd out and lost!" << endl;
}
}
Last edited on Sep 26, 2018 at 6:01pm UTC
Sep 26, 2018 at 6:44pm UTC
Well the first mistake I see is line 16. A const int can contain only one unchangeable value. It can't be 2 or 3 or 12.
Sep 26, 2018 at 7:07pm UTC
I cleaned up your code a bit.
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 57 58 59 60 61 62 63 64 65 66 67
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
int die1;
int die2;
int rollingDice;
int rollingDice2 = 0;
const int SnakeEyes = 1 + 1;
const int Boxcars = 6 + 6;
const int Craps = 2; //or 3 or 12;
srand(time(NULL));
die1 = rand() % 6 + 1;
die2 = rand() % 6 + 1;
rollingDice = die1 + die2;
cout << "Player rolled: " << die1 << " + " << die2 << " = " << rollingDice << endl << endl;
if (rollingDice == 7 || rollingDice == 11)
{
cout << "You won!" << endl;
cin.get();
return 0;
}
if (rollingDice == 2 || rollingDice == 3 || rollingDice == 12)
{
cout << "Craps! You lost!" << endl;
cin.get();
return 0;
}
else
{
cout << "The Point is " << rollingDice << endl << endl;
}
while (rollingDice2 != rollingDice && rollingDice2 != 7) {
die1 = rand() % 6 + 1;
die2 = rand() % 6 + 1;
rollingDice2 = die1 + die2;
cout << "Player rolled: " << die1 << " + " << die2 << " = " << rollingDice2 << endl << endl;
if (rollingDice2 == rollingDice)
{
cout << "You rolled your point! You won!" << endl;
}
if (rollingDice2 == 7)
{
cout << "You seven'd out and lost!" << endl;
}
}
cin.get();
return 0;
}
Last edited on Sep 26, 2018 at 7:08pm UTC
Sep 26, 2018 at 7:30pm UTC
Thank You!
Topic archived. No new replies allowed.