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;
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;
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?
elseif (total = 7,11)
Same problems as #1 and #2 above.
elseif (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.
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";
}
#include <iostream>
#include <iomanip>
#include <ctime>
usingnamespace 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");
}
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.