Hi, I'm new here I searched for any possible way to fix my issues, but I have not found anything that I can understand, so I figured I would post my code here. In my C++ class I was asked to take a craps program and modify it to take in wagers and to also take the gambling part of the game and turn it into a function.

I am not sure if I did it right, but at this point the compiler is giving me problems for my functions not being able to return a 0 and 1 argument on the functions are at the bottom. This has been boggling me for many days, and I don't think I can figure out what's going wrong.

I put the game part into two functions getPoint and continueCraps. What it's suposed to do is take a wager if the wager is valid initiate getPoint and then it can have a win, loss or continue status. If the status is continue then it will go into continueCraps and keep rolling until the roll is equal to myPoint which is a win or 7 which is a loss.

Any help figuring out what I've done wrong, and how to fix it would be greatly appreciated.

``````#include <iostream>
#include <cstdlib> // contains prototypes for functions srand and rand
#include <ctime> // contains prototype for function time
using namespace std;

// enumeration with constants that represent the game status
enum Status { CONTINUE = -1, LOST , WON}; // all caps in constants

// Declare any functions that are defined in this file
int rollDice(int die1, int die2); // rolls dice, calculates and displays sum
int getPoint(int myPoint, int Balance, int wager); // play's the craps game and returns game status
int continueCraps(int myPoint, int Balance, int wager); // Keep playing craps until a win or loss

int main()
{
int Balance = 1000; //betting balance
int wager; // the ammount bet against a round
Status gameStatus;
// randomize random number generator using current time
srand( time( 0 ) ); // seed the random numbers

while(Balance >= 0) // while the balance is positive keep running
{
cout << endl << "Place a bet on your next roll, you might just get lucky!" << endl; // prompt for a wager
cin >> wager; // read the wager

if (Balance >= wager) // keep playing till out of money
{
getPoint(); // find the point
while (gameStatus == CONTINUE) // keep playing while the game status is continue
{
continueCraps();
}

} // end if
else // take a new wager if the previous was too high
{
cout << endl << "You're going broke, lower your wager or get out! Please enter a lower wager than your balance: " << Balance << endl; // if wager is too big prompt for smaller one
cin >> wager;
cout << endl;
} // end else
} // end while

return 0;
} // end main

// roll dice, calculate sum and display results
int rollDice(int die1, int die2)
{
// pick random die values
die1 = 1 + rand() % 6; // first die roll
die2 = 1 + rand() % 6; // second die roll

int sum = die1 + die2; // compute sum of die values
return sum;
} // end function rollDice

int getPoint(int myPoint, int Balance, int wager) //initiates craps
{
Status gameStatus;
int die1, die2;
int sumOfDice = rollDice(die1, die2); // roll dice
cout << "Player rolled " << die1 << " + " << die2 << " = " << sumOfDice << endl; // display roll

// determine game status and point (if needed) based on first roll
if (sumOfDice == 7)
{
Balance = (Balance + wager); // add the wager to balance
cout << "Ahh, you got lucky this time. Your new balance is " << Balance << endl; // display win message
gameStatus = WON; // game won
}
else if (sumOfDice == 11)
{
Balance = (Balance + wager); // add the wager to balance
cout << "You won! Your new balance is " << Balance << endl; // display win message
gameStatus = WON; // game won
}
else if (sumOfDice == 2)
{
Balance = (Balance - wager); // take wager from balance
cout << "Pay up, you rolled craps, you now have " << Balance << endl; // display loss message
gameStatus = LOST; // game lost
}
else if (sumOfDice == 3)
{
Balance = (Balance - wager); // take wager from balance
cout << "You craped out, you only have " << Balance << endl; // display loss message
gameStatus = LOST; // game lost
}
else if (sumOfDice == 12)
{
Balance = (Balance - wager); // take wager from balance
cout << "You rolled craps, you're down to " << Balance << endl; // display loss message
gameStatus = LOST; // game lost
}
else
{
myPoint = sumOfDice; // the sum of this roll is the point
cout << "The point is " << myPoint;
}
return gameStatus;

} // end function playCraps

int continueCraps(int Balance, int wager) // continues to play craps until completion
{
Status gameStatus;
int die1, die2;
int sumOfDice;
int myPoint;
int point = getPoint(myPoint); // the point is myPoint

do
{
// determine game status
sumOfDice = rollDice(die1, die2); // roll again
cout << "Player rolled " << die1 << " + " << die2 << " = " << sumOfDice << endl; // display roll
if ( sumOfDice == point ) // win by making point
{
Balance = (Balance + wager); // add the wager to balance
cout << "You win! You now are the proud owner of " << Balance << endl; // display win message
gameStatus = WON; // game won
}
else if ( sumOfDice == 7 ) // lose by rolling 7 before point
Balance = (Balance - wager); // take wager from balance
cout << "You rolled craps, you're down to " << Balance << endl; // display loss message
gameStatus = LOST; // game lost
} // end do
while ( gameStatus == CONTINUE ); // not WON or LOST
return gameStatus;
} //end funtion continueCraps``````

The problem is that you're calling the functions "getPoint" and "continueCraps" with either no arguments at all

``````getPoint(); // find the point
...
continueCraps();``````

or insufficient number of arguments.

``int point = getPoint(myPoint); // the point is myPoint``

See your declarations for these functions

``````int getPoint(int myPoint, int Balance, int wager); // play's the craps game and returns game status
int continueCraps(int myPoint, int Balance, int wager); // Keep playing craps until a win or loss``````

They both take three integers as arguments.

There is also a problem with the below function:

``````// roll dice, calculate sum and display results
int rollDice(int die1, int die2)
{
// pick random die values
die1 = 1 + rand() % 6; // first die roll
die2 = 1 + rand() % 6; // second die roll

int sum = die1 + die2; // compute sum of die values
return sum;
} // end function rollDice``````

If die1 and die2 are input parameters, then it makes no sense to assign values to them. If they are output parameters, you are only assigning the variables in the function scope. If you want to assign both the variables random values, you need to use references:

``````// roll dice, calculate sum and display results
int rollDice(int& die1, int& die2)
{
// pick random die values
die1 = 1 + rand() % 6; // first die roll
die2 = 1 + rand() % 6; // second die roll

int sum = die1 + die2; // compute sum of die values
return sum;
} // end function rollDice``````

Alright it run's now after adding in the missing variables and references, thank you all for the help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.