Skip to content

Instantly share code, notes, and snippets.

@andresR8
Created November 17, 2020 17:08
Show Gist options
  • Save andresR8/cfd97fea02c8b1b31b446e88140286b8 to your computer and use it in GitHub Desktop.
Save andresR8/cfd97fea02c8b1b31b446e88140286b8 to your computer and use it in GitHub Desktop.
poker_chips
int getNumChips(int val){
int chips[6]={100,50,25,10,5,1};
int numChips=0;
size_t n = sizeof(chips)/sizeof(chips[0]);
for(int i=0; i<n; i++){
numChips += val/chips[i];
val = val % chips[i]; //only works if val is an integer
}
return numChips;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment