Heres my first really c++ game that I did some functions and stuff in. I'm just starting to program reading an eBook I downloaded. Please feel free to leave comments or suggestions.
Feel free to put my reputations up if you thinks it's good for a beginnerCode:/******************** * * Craps Game * main.cpp * ********************/ #include <iostream> #include <time.h> #include <stdlib.h> using namespace std; void showIntro (void); void showInformation (unsigned long playerMoney); short playerBet (void); short diceRoll (void); unsigned short moneyCalc (short diceValue, short getBet, short betMoney); unsigned long getAmount (void); int main () { unsigned long playerEarned; unsigned long playerMoney; short diceValue; short getBet; short betMoney; showIntro (); playerMoney = 1000; do { showInformation (playerMoney); getBet = playerBet (); betMoney = getAmount (); diceValue = diceRoll (); playerEarned = moneyCalc (diceValue, getBet, betMoney); playerMoney -= betMoney; if (playerEarned == 0) { cout << "You lost. The number was : " << diceValue; cout << endl << endl; } else { cout << "You earned : " << playerEarned - betMoney << " dollars," << endl; cout << "The number was : " << diceValue; cout << endl << endl; playerMoney += playerEarned; } } while (playerMoney > 100); cout << "Game over. You're gonna need that $" << playerMoney << "for the taxi ride home."; cout << endl << endl; return 0; } void showIntro (void) { cout << "Welcome to Craps v1. Written by : Ryan Nielson" << endl; cout << endl; cout << "Here are the rules :"<< endl << endl; cout << "-You start of with $1000 to bet." << endl << endl; cout << "-You bet in amounts of $10 or $100." << endl << endl; cout << "-You can bet on numbers 2 and 12 which will win you a ratio of 5 : 1." << endl << endl; cout << "-You can bet on numbers 4 and 10 which will win you a ratio of 2.5 : 1." << endl << endl; cout << "-You can bet on numbers 6 and 8 which will win you a ratio of 1.5 : 1." << endl << endl << endl; cout << "-Have fun and enjoy the game!" << endl << endl; } void showInformation (unsigned long playerMoney) { cout << "You have " << playerMoney << "dollars." << endl << endl; } short playerBet (void) { unsigned short betType; /*Get the bet ----------------------------------------------------------------------------*/ cout << "What numbers would you like to bet on ?" << endl; cout << "(1. '2/12', 2. '4/10', 3. '6/8') : "; cin >> betType; if ((betType == 1) || (betType == 2) || (betType == 3)) { return betType; } else { return 1; } } short diceRoll (void) { short diceValue; srand (time (NULL)); // Get Dice Value diceValue = (rand () % 11) + 2; if ((diceValue == 4) || (diceValue == 10)) // Makes 4/10 harder to get. { srand (time (NULL)); diceValue = (rand () % 12) + 1; } if ((diceValue == 2) || (diceValue == 12)) // Makes 2/12 harder to get. { srand (time (NULL)); diceValue = (rand () % 12) + 1; if ((diceValue == 2) || (diceValue == 12)) // Makes 2/12 harder to get. { srand (time (NULL)); diceValue = (rand () % 12) + 1; } } return diceValue; } unsigned short moneyCalc (short diceValue, short getBet, short betMoney) { unsigned long playerEarned = 0; switch (getBet) { case 1: if ((diceValue == 6) || (diceValue == 8)) { playerEarned = betMoney * 1.5; } break; case 2: if ((diceValue == 4) || (diceValue == 10)) { playerEarned = betMoney * 2.5; } break; case 3: if ((diceValue == 2) || (diceValue == 12)) { playerEarned = betMoney * 5; } break; default : playerEarned = 0; break; } return playerEarned; } unsigned long getAmount (void) { unsigned short betAmount; cout << "How much would you like to bet? $10 or $100 : "; cin >> betAmount; /*If the betting amounts are off----------------------------------------------------------------*/ if (betAmount < 10) { betAmount = 10; } else if (betAmount > 100) { betAmount = 100; } return betAmount; }![]()
I'm j/k.
But if you want to go right ahead lol



LinkBack URL
About LinkBacks



