You can create functions for almost anything, just think of groups of code that you can put together by themselves. For instance, I took your code, and created a function called startgame.
Code:
//startgame function prototype
void startgame(int &betamt, int &playerstot, int &betchoice);
//startgame function definition
void startgame(int &betamt, int &playerstot, int &betchoice)
{
bool validbetamt = true;
cout << "Let's play some roulette!" << endl
<< "You will start with $1000." << endl;
//This do-while statement asks for the amount of the bet and
//verifies that it is a valid amount
do(
cout<< "What is your bet ( 1 - 1000, 0 to quit)?" << endl;
cin >> betamt;
if(betamt > playerstot)
{
cout<<"The amount you bet is greater than the amount you "
<<"have, please try again. " <<endl;
validbetamt = false;
}
}while (!validbetamt)
if (betamt != 0)
{
cout << "What do you want to bet on?" << endl
<< " 1 - ODD" << endl
<< " 2 - EVEN" << endl
<< " 3 - First group (1 - 12)"<< endl
<< " 4 - Second group (13 - 24)" << endl
<< " 5 - Third group (25 - 36)" << endl
<< " 6 - specific number" << endl
<< "Enter choice (1-6): " << endl;
cin >> betchoice;
}
}
so now your main program will look like this:
Code:
#include <iostream>
#include <cstdlib>
#include <ctime>
using std::cout;
using std::endl;
using std::cin;
int main ()
{
int bet, choice = 0;
int playerstotal
startgame(bet, playerstotal, choice);
switch (choice) {
case 1:
cout << "You chose odd" << endl;
break;
case 2:
cout << "You chose even" << endl;
break;
case 3:
cout << "You chose first group (1 - 12)"<< endl;
break;
case 4:
cout << "You chose second group (13 - 24)"<< endl;
break;
case 5:
cout << "You chose third group"<< endl;
break;
case 6:
cout << "You chose specific number" << endl;
break;
default:
cout << "Program should never get here!!" << endl;
}
Once you get this working correctly, you can move on to the next piece. By creating functions, you can work on the program piece by piece, and fixing syntax and/or logic errors can be done as you code, and can be easier to narrow down. (My code has not been compiled, so there may be errors) (By the way, you should use code tags for your code, it makes it much easier to read). One suggestion, perhaps the 'choice' should be a 'char' instead of an int.