DICE PROBLEM HELPP!

I have the general set up for a dice game. Now i need to :

Extend the program to allow a player Save the players first dice roll if it's a 4,5,6,8,9,10 call it the point. Continue rolling until one of the following two things happens. If the player rolls a 7 BEFORE getting the point then the player wins and the turn is over. If any number besides the 7 or "point" is rolled nothing happens the player keeps rolling, once the number is rolled if it is a 7 the player loses, however if it is the "point" then the player wins.

Here is what I have so far. I'm at a loss as to where to go next. Please help me!


#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;

int main()
{
int die1,die2,total;

die1 = rand()%6 + 1;
die2 = rand()%6 + 1;
total = die1 +die2;



if (die1= 4,5,6,8,9,10 )
{
cout <<"Roll 1 - Your point is "<<die1<<"\n";
die1++;
}
else if (total = 7,11)
cout <<"Yea! You won with a 7 on the first roll.\n";
else if (total != 7 || total != die1)
cout <<"Roll 2: "<<die1;

system("pause");
}
Lots of things wrong here:

if (die1= 4,5,6,8,9,10 )
1) You're using the assignment operator, not the comparison operator.
2) You can't put multiple values on the right hand side. You must do each comparison individually.
if (total== 4 || total == 5 || total == 6 || total == 8 || total == 9 || total == 10)
3) You're comparing die1, not total.

1
2
3
4
cout <<"Roll 1 - Your point is "<<die1<<"\n";]/code]
The point is the total of the two die.  Not die1.

[code]die1++;

Why are you incrementing die1?

else if (total = 7,11)
Same problems as #1 and #2 above.

else if (total != 7 || total != die1)
Not sure what this line is supposed to be doing.

cout <<"Roll 2: "<<die1;
You never called rand() again to get new values for die1 and die2.

You never call srand(time(NULL));
Your program will use the same sequence of random numbers every time it is run.

PLEASE USE CODE TAGS (the <> formatting button) when posting code. It makes it easier to read your code and to respond to your post.

Last edited on
Okay I think I changed what you recommended and I figured a little more out on my own but it's still not printing out the way it should. It's pretty close but not right. Any other suggestions?


#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;

int main()
{
int die1,die2,total;

die1 = rand()%1;
die2 = rand()%1;

int num = 1;
srand(time(NULL));
if (die1 = 4 )
{
cout <<"\nRoll "<<num++<<" - Your point is "<<die1;
}
if (die1= 5)
{
cout <<"\nRoll "<<num++<<" - Your point is "<<die1;
}

if (die1= 6)
{
cout <<"\nRoll "<<num++<<" - Your point is "<<die1;
}
if (die1= 8)
{
cout <<"\nRoll "<<num++<<" - Your point is "<<die1;
}
if (die1= 9)
{
cout <<"\nRoll "<<num++<<" - Your point is "<<die1;
}
if (die1= 10 )
{
cout <<"\nRoll "<<num++<<" - Your point is "<<die1;
}




if (die1 = 7)
{
cout <<"\nYea! You won with a 7 on the first roll.\n";

}

if (die1 = 11)
{
cout <<"\nYea! You won with a 7 on the first roll.\n";
}






if (die2 = 4 )
{
cout <<"\nRoll "<<num++<<" - "<<die1;
}
if (die2= 5)
{
cout <<"\nRoll "<<num++<<" - "<<die1;
}

if (die2= 6)
{
cout <<"\nRoll "<<num++<<" - "<<die1;
}
if (die2= 8)
{
cout <<"\nRoll "<<num++<<" - "<<die1;
}
if (die1= 9)
{
cout <<"\nRoll "<<num++<<" - "<<die1;
}
if (die2= 10 )
{
cout <<"\nRoll "<<num++<<" - "<<die1;
}

if (die2 = 7)
{
cout <<"\nYou lost!.\n";

}

if (die2 = 11)
{
cout <<"\nYou lost!.\n";

}


system("pause");
}
I will not reply futher until you edit your post and apply code tags as requested in my previous response.

http://v2.cplusplus.com/articles/jEywvCM9/
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;

int main()
{
int die1,die2,total;

die1 = rand()%1;
die2 = rand()%1;

int num = 1;
srand(time(NULL));
if (die1 = 4 )
{
cout <<"\nRoll "<<num++<<" - Your point is "<<die1;
}
if (die1= 5)
{
cout <<"\nRoll "<<num++<<" - Your point is "<<die1;
}

if (die1= 6)
{
cout <<"\nRoll "<<num++<<" - Your point is "<<die1;
}
if (die1= 8)
{
cout <<"\nRoll "<<num++<<" - Your point is "<<die1;
}
if (die1= 9)
{
cout <<"\nRoll "<<num++<<" - Your point is "<<die1;
}
if (die1= 10 )
{
cout <<"\nRoll "<<num++<<" - Your point is "<<die1;
}




if (die1 = 7)
{
cout <<"\nYea! You won with a 7 on the first roll.\n";

}

if (die1 = 11)
{
cout <<"\nYea! You won with a 7 on the first roll.\n";
}






if (die2 = 4 )
{
cout <<"\nRoll "<<num++<<" - "<<die1;
}
if (die2= 5)
{
cout <<"\nRoll "<<num++<<" - "<<die1;
}

if (die2= 6)
{
cout <<"\nRoll "<<num++<<" - "<<die1;
}
if (die2= 8)
{
cout <<"\nRoll "<<num++<<" - "<<die1;
}
if (die1= 9)
{
cout <<"\nRoll "<<num++<<" - "<<die1;
}
if (die2= 10 )
{
cout <<"\nRoll "<<num++<<" - "<<die1;
}

if (die2 = 7)
{
cout <<"\nYou lost!.\n";

}

if (die2 = 11)
{
cout <<"\nYou lost!.\n";

}


system("pause");
} 
-You need to look up the difference between = and ==.

= is assignment.
== is for comparing 2 values.

You should be using == in all of your if statements.

-You should call srand() before you make any rand() function calls.
-You could look up how calling rand() works, you will get 0 every time right now.
Thank you for adding code tags.

In addition to what James2250 said, you are still confusing die1, die2 and total.

At lines 10 and 11 you calculate (incorrectly) the value of each die rolled. In craps, the point is the sum of the two die (your total variable).

At lines 28, 32 and 36, you are trying to compare the value of die1 to 8, 9 or 10. A die only has values from 1 to 6. You want to be comparing total, not die1. I pointed this out before. See #3 in my first post.
Topic archived. No new replies allowed.