I have created a dice betting game. I cannot get the loop to run correctly could someone help me with finding the issue? -
okay need getting bank not reset 100 after each time loop runs. have tried many ways can't seem work. please me few explanations , examples?
#include <iostream> #include <stdio.h> #include <cstdlib> #include <ctime> using namespace std; int displaystats(int gamesplayed, int wins, int losses, int bank); int main() { int bank = 100;//intital bank value int bet = 0;//desired wager int wins = 0;//games won int losses = 0;//games lost int gamesplayed = 0;//how many rounds played int compdice1 = 0;//first rolled dice computer int compdice2 = 0;//second rolled dice computer int playdice1 = 0;//first rolled dice player int playdice2 = 0;//seconds rolled dice player int newdice = 0;//the dice risk wager int comproll = 0;//the sum of computers roll int playroll = 0;//the sum of players roll { if (bank < 0) { cout << "you have " << bank << " coins in bank." << endl; cout << "i sorry out of money." << endl; displaystats(gamesplayed, wins, losses, bank); break; } else if (bank > 0) { cout << "you have " << bank << " coins in bank." << endl; cout << "how many coins bet? "; cin >> bet; compdice1 = (rand() + time(0)) % 6 + 1;//computer dice compdice2 = (rand() + time(0)) % 6 + 1;//computer second dice playdice1 = (rand() + time(0)) % 6 + 1;//player dice playdice2 = (rand() + time(0)) % 6 + 1;//player second dice comproll = compdice1 + compdice2;//computer sum playroll = playdice1 + playdice2;//player sume cout << "your roll " << playdice1 << " , " << playdice2 << " sume of " << playroll << endl; if (playroll < comproll) { char option;//option roll dice cout << "you win!" << endl; cout << "would roll third dice earn 1.5 times bet, yes or no? "; cin >> option; if (option == 'yes') { int newroll;//the new sum of 3 dice int newdice;//the roll newdice = (rand() + time(0)) % 6 + 1; newroll = playroll + newdice;//the value of players roll if (newroll > comproll) { cout << "the computer rolled " << comproll << endl; cout << "you rolled higher computer therefore, sorry lose round." << endl; cout << "your bank equals " << bank - bet << endl; losses++; gamesplayed++; } else if (newroll < comproll) { cout << "you win!" << endl; cout << "your bank equals " << bank + (1.5 * bet) << endl; wins++; gamesplayed++; } } else if (option == 'no') { cout << "your bank equals " << bank + bet << endl; wins++; gamesplayed++; } } else if (playroll > comproll) { cout << "the computer rolled " << comproll << endl; cout << "you rolled higher computer therefore, sorry lose round." << endl; cout << "your bank equals " << bank - bet << endl; losses++; gamesplayed++; } else if (playroll = comproll) { cout << "the computer rolled " << comproll << endl; cout << "i sorry lose double bet!" << endl; cout << "your bank equals " << bank - (2 * bet) << endl; losses++; gamesplayed++; } } } while (bank > 0); int stats = displaystats(gamesplayed, wins, losses, bank); cout << "your stats " << stats << endl; return 0; } int displaystats(int gamesplayed, int wins, int losses, int bank) { cout << "games played: " << gamesplayed << endl; cout << "wins: " << wins << endl; cout << "losses: " << losses << endl; cout << "bank total: " << bank << endl; return (gamesplayed, wins, losses, bank); }
your problem bank "resetting" never subtracted bet bank. see following code, hope helps.
cout << "you have " << bank << " coins in bank." << endl; cout << "how many coins bet? "; cin >> bet; //this line forgot. bank = bank - bet
if win, may want later on add money bank. (but you.) hope helps.
edit:
here paste-bin full code requested: http://pastebin.com/hzvrxjxl
also, if solves problem, appreciate if mark answer others don't spend time answering problem has been solved.
edit 2:
this has (as far can tell) fixed , commentated version of code. hope helps: http://pastebin.com/miqjy4b5
Comments
Post a Comment