Hey guys, I am having trouble with my class assignment. This is what I am supposed to do:
To get full credit on this assignment you must use loops and decisions. To get random numbers for your dice in your program you will need to use the rand() and srand() library functions. (See the appendix of the book for examples in the book on how to use rand() and srand().)
A player rolls two dice. Each die has six faces. These faces contain 1, 2, 3, 4, 5 and 6 spots. After the dice have come to rest, the sum of the spots on the two upward faces is calculated. If the sum is 7 or 11 on the first roll, the player wins. If the sum is 2, 3 or 12 on the first roll (called “craps”), the player loses (i.e. the “house” wins). If the sum is 4, 5, 6, 8, 9 or 10 on the first roll, then that sum becomes the player’s “point.” To win, you must continue rolling the dice until you “make your points”. The player loses by rolling a 7 before making the point.
It would be very helpful in this program to use boolean variables to keep track of things such as if the user has won the game or not, and if the game is over or not.
So far the program is working. I am stuck on keeping track of when the player rolls more than once.
uhm...you mean how many times it has looped before quitting? Or do you mean whether they've chosen to roll more than one dice that round?
If the former, then you'll need an extra variable called 'loop_count' or something along those lines then just before the while loop finishes, increment loop_count.
I am trying to get it to calculate for the "points". Lets say I roll a 10. I need to get it to keep track of the 10 when I continue to roll. I either need to roll another 10 or lose by rolling a 7.
Right now its only calculating for my first roll. I can only win if I roll a 7 or 11. If I don't roll those it keeps looping back to my first roll tell I roll a losing number. It won't keep track of my "point rolls"
No, If I roll a 10 it is called a "point" I need to roll another 10 inorder to win the game. If I roll anything else it continues to loop until I roll another 10 or a 7, 7 being I lost the game.
#include <locale> // to use std::toupper function
usingnamespace std;
//put std:: before each STL thing
//or do this:
/*
using std::cout;
using std::cin;
using std::endl;
//similar for anything used a lot
*/
bool Quit = false;
while (!Quit) {
....
std::cout << "Would you like to play again" << std::endl ;
std::cin >> repeat;
repeat = std::toupper(repeat);
if(repeat != 'Y') {
Quit = true;
}
}
//execution continues here
How would that look in code? To store another roll inside my first roll statement? Sorry I am new to this. I feel like I almost have it just missing something.
if (roll1 == 7 || roll1 == 11)
{
if (roll2 == 0) // A check to see if it has already been filled. This is not a good solution...
{
roll2 = roll1;
}
elseif ( roll 1 == roll 2 )
{
//Win
}
cout << "You win! Would you like to play again? [Y/N]:" << endl;
cin >> repeat;
}