Yam Code
Sign up
Login
New paste
Home
Trending
Archive
English
English
Tiếng Việt
भारत
Sign up
Login
New Paste
Browse
#include<stdio.h> #include<stdlib.h> #include<time.h> #define MONEY_START 1000 #define MIN_VALUE 1 #define MAX_VALUE 6 int getInt(int, int); int menu(); int roll(int, int); void buyChips(int *money, int *chips); void sellChips(int *money, int *chips); void playCraps(int *money, int *chips); void playArupsGameOfDice(int *money, int *chips); void statusReport(int *money, int *chips); int main(){ int money = MONEY_START; int chips = 0; int isContinue = 1; printf("You have $%d.\n", money); do { int choose = menu(); switch(choose){ case 1: buyChips(&money, &chips); break; case 2: sellChips(&money, &chips); break; case 3: playCraps(&money, &chips); break; case 4: playArupsGameOfDice(&money, &chips); break; case 5: statusReport(&money, &chips); break; default : printf("GoodBye !\n"); isContinue = 0; } } while(isContinue == 1); } //Functions are in here int getInt(int minValue, int maxValue){ int value; char check; //42a do { int rc = scanf("%d%c", &value, &check); fpurge(stdin); if(rc != 2 || check != '\n'){ printf("Invalid value!\n"); } else if (value > maxValue || value < minValue){ printf("Value out of range!\n"); } else{// rc == 2 && check == '\n' return value; //break out of function } } while(1); } int menu() { int choose; printf("______________)***********(_________________\n"); printf("Welcome to the Casino. Here are your choices: \n"); printf("1) Buy chips \n"); printf("2) Sell chips \n"); printf("3) Play Craps \n"); printf("4) Play Arup's Game of Dice \n"); printf("5) Status Report \n"); printf("6) Quit \n"); choose = getInt(MIN_VALUE, MAX_VALUE); return choose; } void buyChips(int *money, int *chips) { printf("How much cash do you want to spend for chips?\n"); int cash = getInt(0, 100000); if(cash > *money){ printf("Sorry, you do not have that much money. No chips bought.\n"); } else{ *money -= (cash/11)*11; *chips += cash/11; printf("You bought %d chips.\n", cash/11); } } void sellChips(int *money, int *chips){ printf("How many chips you want to sell?\n"); int chipSell = getInt(0, 100000); if(chipSell > *chips){ printf("Sorry, you do not have many chips. No chips sold.\n"); } else{ *chips -= chipSell; *money += chipSell*10; printf("You sold %d chips.\n", chipSell); } } void statusReport(int *money, int *chips){ printf("You currently have $%d left and %d chips.\n", *money, *chips); } //game int roll(int minValue, int maxValue){ srand( (unsigned)time( NULL ) ); return minValue + rand() % (maxValue + 1 - minValue); } void playCraps(int *money, int *chips){ printf("How many chips would you like to bet?\n"); int chipsBet = getInt(0, *chips); if(chipsBet == 0){ printf("Sorry, that is not allowed. No game played.\n"); } else{ *chips -= chipsBet; printf("Press 'r' and hit enter for your first roll.\n"); getchar(); int rollTwoDice = roll(2,12); printf("You rolled a %d.\n", rollTwoDice); if(rollTwoDice == 7 || rollTwoDice == 11){ printf("You win !\n"); *chips += chipsBet*2; } else if(rollTwoDice == 2 || rollTwoDice == 3 || rollTwoDice == 12){ printf("You lose !\n"); } else{ int k = rollTwoDice; int isStop = 0; do{ printf("Press 'r' and hit enter for your next roll.\n"); getchar(); int nextRoll = roll(2,12); printf("You rolled a %d.\n", nextRoll); if(nextRoll == k){ printf("You win!\n"); *chips += 2*chipsBet; isStop = 1; } else if(nextRoll == 7){ printf("Sorry, you have lost.\n"); isStop = 1; } } while(isStop == 0); } } } void playArupsGameOfDice(int *money, int *chips) { printf("How many chips would you like to bet?\n"); int chipsBet = getInt(0, *chips); if(chipsBet == 0){ printf("Sorry, that is not allowed. No game played.\n"); } else{ *chips -= chipsBet; printf("Press 'r' and hit enter for your first roll.\n"); getchar(); int rollTwoDice = roll(2,12); printf("You rolled a %d.\n", rollTwoDice); if(rollTwoDice == 11 || rollTwoDice == 12){ printf("You win !\n"); *chips += chipsBet*2; } else if(rollTwoDice == 2){ printf("You lose !\n"); } else{ int k = rollTwoDice; int point; printf("Press 'r' and hit enter for your next roll.\n"); getchar(); int nextRoll = roll(2,12); printf("You rolled a %d.\n", nextRoll); point = nextRoll; if(point > k){ printf("You win!\n"); *chips += 2*chipsBet; } else{ printf("Sorry, you have lost.\n"); } } } }
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Tiếng Việt
भारत