i knew comp sci would pay off
/* Program is to simulate a casino game*/
#include <stdio.h>
#include <stdlib.h>
void mainmenu(void);
int pairofdice(void); /*c represents chips, k represents cash*/
int craps(int c);
int arupsdice(int c);
int buychips(int k);
int sellchips(int c);
int sellallchips(int c);
void statusreport(int c, int k);
int main (void) {
int cash=1000, numchips=0, change_in_cash=0;
int menuchoice, loop=1;
while (loop == 1){
mainmenu();
scanf("%d", &menuchoice);
printf("\n");
if (menuchoice <= 6 && menuchoice >=1){
if (menuchoice == 1){
change_in_cash = buychips(cash);
cash -= change_in_cash;
numchips += (change_in_cash/11);
change_in_cash = 0;
}
// you put an if else here
if (menuchoice == 2){
change_in_cash = sellchips(numchips);
cash += change_in_cash;
numchips -= (change_in_cash/10);
change_in_cash = 0;
}
//here
if (menuchoice == 3){
numchips = craps(numchips);
}
//here
if (menuchoice == 4){
numchips = arupsdice(numchips);
}
//here
if (menuchoice == 5){
statusreport(numchips, cash);
}
// here again..
if (menuchoice == 6){
change_in_cash = sellallchips(numchips);
cash += change_in_cash;
printf("Thank you for playing Casino.\nYou have finished with a total of $%d.", cash);
loop = 0;
}
}
else {
printf("Not a valid choice.");
}
}
return 0;
}
void mainmenu (void) {
printf("Welcome to the Casino. Please make a selection\n");
printf("1)Buy chipe\n2)Sell chips\n3)Play Craps\n4)Play Arup's Game of Dice\n5)Status Report\n6)Quit\n");
}
int pairofdice(void) {
int total, a, b;
a = 1+rand()%6;
b = 1+rand()%6;
total = a+b;
return total;
}
int craps(int chips) {
int chips_won, total_chips, how_many, dice, k, pop=1;
printf("You have %d chips\n", chips);
printf("How many chips would you like to bet? ");
scanf("%d", &how_many);
printf("\n");
if (how_many > chips){
printf("NOT ENOUGH CHIPS!!! No game played\n");
return 0;
}
else {
dice = pairofdice();
printf("You rolled a %d.\n", dice);
if (dice == 7 || dice==11){
printf("You Win!!! %d chips have been added to your total.\n", how_many);
//how many is not an int.. cant have a space:P
total_chips = chips + how_many;
}
// its either if or else, not both
if (dice == 2 || dice == 3 || dice == 12){
printf("You Lose. %d chips have been deducted from your total.\n", how_many);
//same here
total_chips = chips - how_many;
}
else {
while (pop==1){
k = pairofdice(); // forgot a semi colon
if (k == dice){
printf("You Win!!! %d chips have been added to your total.\n", how_many);
//jeez man.. again
total_chips = chips + how_many;
pop = 0;
}
// what is it with you and if elses?
if (k == 7){
printf("You Lose. %d chips have been deducted from your total.\n", how_many);
// how many instead of how_many
total_chips = chips - how_many;
pop = 0;
}
}
}
}
return total_chips;
}
int arupsdice(int chips) {
int chips_won, total_chips, how_many, dice, k;
printf("You have %d chips\n", chips);
printf("How many chips would you like to bet? ");
scanf("%d", &how_many);
printf("\n");
if (how_many > chips){
printf("NOT ENOUGH CHIPS!!! No game played\n");
return 0;
}
else {
dice = pairofdice();
printf("You rolled a %d.\n", dice);
if (dice == 12 || dice == 11){
printf("You Win!!! %d chips have been added to your total.\n", how_many);
total_chips = chips + how_many;//how many again
}
// if else.. pick one or the other
if (dice == 2){
printf("You Lose. %d chips have been deducted from your total.\n", how_many);
total_chips = chips - how_many; // how many.. yet again
}
else {
k = pairofdice(); // semi colon
if (k > dice){
printf("You Win!!! %d chips have been added to your total.\n", how_many);
total_chips = chips + how_many;// how many again again
}
else{
printf("You Lose. %d chips have been deducted from your total.\n", how_many);
total_chips = chips - how_many; // yeah.. you guessed it!
}
}
}
return total_chips;
}
int buychips(int cash) {
int how_many, cash_required; // not a function, dont need the ( at the end
printf("You have $%d\n", cash);
printf("How many chips would you like to buy? ");
scanf("%d", &how_many);
printf("\n");
cash_required = (how_many*11);
if (cash_required > cash){
printf("NOT ENOUGH CASH!!!\n");
return 0;
}
else {
return cash_required;
}
}
int sellchips(int chips) {
int how_many, cash_made; // not a function, dont need ( at the end
printf("You have %d chips\n", chips);
printf("How many chips would you like to sell? ");
scanf("%d", &how_many);
printf("\n");
cash_made = (how_many*10);
if (how_many > chips){
printf("NOT ENOUGH CHIPS!!!\n");
return 0;
}
else {
return cash_made;
}
}
int sellallchips(int chips) {
int cash_made;
cash_made = (chips*10);
return cash_made;
}
void statusreport(int chips, int cash) {
printf("Status: You currently have %d chips and $%d.", chips, cash);
}
try that.. it worked for me on C++.. your biggest problems were when you put if else.. you put and if OR an else.. not both... how many is not a variable.. how_many is... you forgot a semi colon here and there.. and put some ) in some places... didnt take too much.. i put comments wherever i changed something..
Marc