### Functions

Hello, this is one of my first posts with c++ help soo yeah. But today i need help with functions. In particular a program that deals with functions. Its a Roulette program. The user is supposed to place a bet (1-6) and place a money bet and it randomizes a number and if they win, they get a cash payout (in the option that they chose). I'm horrible at functions so help me out pls.

This was done on Borland C++

#include <iostream.h>
#include <conio.h>
#include <math.h>
#include <stdlib.h>

void placeBetType(int Intialbet,int Bt);
void placeBetAmount(int Intialmoney,int moneybet);
void spinWheel(int rand);
double CurrentDollars(int CD=500);

main(){
int Cd=500,Bt;
int intialbet,moneybet;
int wheelspun;
cout<<"Current Dollars= "<<Cd;
/////////////////// VVV Money bet VVV///////////////////////
cout<<"How much money would you like to bet? (\$1-\$100)";
cin>>moneybet;
placeBetType;
spinWheel;

return 0;
}

void placeBetAmount(int Intialbet,int CD)
{
int intialbet,Winnings,Bt;
switch(placeBetType,rand,CD,Intialbet){
case 1:
{
Winnings=Intialbet + CD;
cout<<"You have guessed the right even number! You're current dollar is "<<Winnings;
}
case 2:
{
Winnings=Intialbet + CD;
cout<<"You have guessed the right odd number! You're current dollar is "<<Winnings;
}

case 3:
{
Winnings=(Intialbet*3) + CD;
cout<<"You have guessed the right number in (1-12)! You're current dollar is "<<Winnings;
}
case 4:
{
Winnings=(Intialbet*3) + CD;
cout<<"You have guessed the right number in (13-24)! You're current dollar is "<<Winnings;
}
case 5:
{
Winnings=(Intialbet*3) + CD;
cout<<"You have guessed the right number in (25-36)! You're current dollar is "<<Winnings;
}
case 6:
{
Winnings=(Intialbet*36) + CD;
cout<<"You have guessed a single number! You're current dollar is "<<Winnings;
}
if(rand!=Bt)
{
cout<<"You have not guess the right number, you lose your bet";
Winnings=Intialbet-CD;
}

}
}
void spinWheel(int rand)
{
randomize();
int Rand;
Rand=random(37);
return spinWheel;
}
int placeBetType(int Bt);
{
int Bt,X,number;
cout<<"Current Cash \$"<<CD<<"\n\n";

cout<<"1:Even number (1x payout)\n";
cout<<"2:Odd number (1x payout\n)";
cout<<"3:First third between 1-12 (3x payout)\n";
cout<<"4:Second third between 13-24 (3x payout)\n";
cout<<"5:Last third between 25-36 (3x payout)\n";
cout<<"6:Picking a single number (36x payout)";
cout<<"If you don't pick the number that was chosen, you lose your bet";
cin>>Bt;

if (Bt>=1 || Bt <=6)
{
cin>>number;
}

return placeBetType;
}

double CurrentDollars(int CD);
{
int Cd=500;
return CD;
}
I am sorry I did not look through all your code but it is already enough to point out that the following function definition has no any sense

double CurrentDollars(int CD);
{
int Cd=500;
return CD;
}

The parameter is not used. So it is not clear what is the purpose to define the function with the parameter. Also C++ does not allow to define a name in the outermost scope of a function that coinsides with a parameter name.
Last edited on
Its all good, I kinda just did some mumbo jumbo. But my real question is when using a function, how do you get other info from one function and use it in another? Thats like one of the problems i have with this program
To pass info from calling code into a function, you pass it as an argument. So, for example, your method spinWheel takes an integer argument called rand. You can use that argument inside your function.

To pass info from a function back to the calling code, you have several possibilities:

1) You can return a single value. So, for example, your placeBetType returns the value of an integer. I notice in your code you're trying to declare a variable called placeBetType, but you haven't defined that variable anywhere inside your function, so it won't compile. Also, you should avoid using the same name for more than one thing, as it will make your code confusing. If your function is called placeBetType, the variable that it returns should be named something different, for clarity.

2) You can pass in a pointer to some memory that the calling code has allocated to store the value you want to pass back.

3) You can pass in a reference to a variable. This means that when the function sets the value of the variable, the calling code will be able to access that new value.
When defining functions and prototyping them you can't pass variables into them without them being sent from main() or previously returned to main(). You also can't assume that even though you declared a variable in a certain function that it will be automatically viewed by the compiler everywhere else in your code.