Help with Craps.. Still not Understanding

We must create a craps game...
The teacher suggest we use the following as a plan to attack:

0. Use two global variables to represent the dice.
1. Define local variables
3. Lost Flag [boolean]
4. Won Flag [boolean]
5. Holds point "target" which has to be re-rolled to win [int]
6. Holds value of re-rolls [int]
7. seed random number generator
8. generate first die roll [store result to point variable]
9. show results to console window
10. check if lost on first roll [set lost flag]
11. check if won on first roll [set won flag]
12. while we haven’t won or lost loop to re-roll until point is made or we crap out
0. display point
1. hold console window open
2. roll and show dice [store result to point variable]
3. check if roll is equal to point [set won flag]
4. check if we crapped out [set lose flag]
8. display loss status if lost
9. display won status if won

My Code is Nothing like that: The following is my code:

//Christy Windham
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

int GetRandom(int a, int b)
int r;
return (r);

int main()
int dieOne = 0;
int dieTwo = 0;
int roll = 0;
int point = 0;
int win = 0;
int loss = 0;
double odds = 0;
srand((unsigned int)time(NULL));

dieOne = (rand()%6)+1; //Creates dice
dieTwo = (rand()%6)+1;
roll = dieOne + dieTwo;

cout<<dieOne<<" plus "<<dieTwo<<" = "<<roll<<endl; //Prints random dice numbers to screen

if(roll==7 || roll==11) //Win on first roll
else if (roll==2 || roll==3 || roll==12)// Lose on first roll
else if (roll==4 || roll==5 || roll==6 || roll==8 || roll==9 roll==10)
point=roll;//point set

dieOne=(rand()%6)+1;//rolls dice again

cout<<dieOne<<" plus "<<dieTwo<<" = "<<roll<<endl;

if(roll==point)//wins if player rolls point
else if(roll==7)//lose if player rolls 7
else if(roll!=7 && roll!=point) //nothing otherwise

}while(roll!=point && roll!=7);//keep going until point or 7 is rolled

That is nothing like he wants it though. Fisrt I must make a function to create random numbers when the dice is rolled. For instance, if a number is passed through that function it will give me a random result.

He wants this in the program basically:

Show that you can create a function that generates a random number from
1 to n and return the generated random number. Also show that you can display
the random number returned by this function to the console window.

Last edited on
Topic archived. No new replies allowed.