- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
因此,在我的最终项目(使用从纸牌类继承的二十一点和扑克模拟器)中,我们必须跟踪用户的赌注和总金额。但是,在我的代码中,它做了非常奇怪的事情。例如:如果您的总资金为 1000000000 美元,您下注 100 并赢回 200,那么您的新总资金现在等于 199 美元
我的程序在执行此操作和不执行此操作之间来回切换。这太令人抓狂了,我不知道为什么会这样。以下是我的主要功能,以及处理每个扑克游戏的两个功能。如果有人认为需要更多代码来回答,尽管我很乐意包含类 header 和实现文件。感谢所有可能提供帮助的人!以下是我的主要功能,以及处理每个游戏的两个功能:
unsigned int handlePoker(unsigned int);
unsigned int handleBlackJack(unsigned int);
//main function:
//asks the user what game they want to play
//then calls a function for the appropriate
//game chosen
int main()
{//two choices:
//one for quitting the program
//the other for whichever game they want
char yesOrNo;
char choice;
unsigned int totalMoney;
cout<< "please enter a starting amount to bet with"<<endl;
cin>>totalMoney;
cout<<"would you like to play?"<<endl;
cout<<"enter 'y' for yes and 'n' for no"<<endl;
cin>>yesOrNo;
do{
//ask the user which game they want
cout<<"would you like to play poker or black jack?"<<endl;
cout<<"input '1' for poker and '0' for blackjack"<<endl;
cin>>choice;
if(choice == '1')
{
totalMoney = handlePoker(totalMoney);
}//end if
else if(choice == '0')
{
totalMoney = handleBlackJack(totalMoney);
}//end else if
else
{
cout<<"I'm sorry, the input you entered was invalid"<<endl;
cout<<"please try again"<<endl;
cin.clear();
}//end else
cout<<"would you like to try again?"<<endl;
cout<<"('y' for yes, or 'n' for no)"<<endl<<endl;
cin>>yesOrNo;
}while(yesOrNo == 'y' || yesOrNo == 'Y'); //end do while loop
return 0;
}//end int main
//handle poker:
//a void function which takes an
//unsigned integer value
//the function declares a "poker" object
//and uses it's void functions to sim a poker game
unsigned int handlePoker(unsigned int tot)
{
unsigned int multiply;
unsigned int betMonies;
unsigned int win;
poker round;
cout<<"how much do you want to bet?"<<endl;
cin>>betMonies;
//if the bet money entered was valid
// we begin playing
if(betMonies < tot)
{//big if begin
//ask if they want a better hand
round.betterHand();
//set the number we multiply your money by
multiply = round.rewardMoney();
//if multiply is 0
//then the user has lost this hand
//we inform them as such, and subtract
//their bet money from their total money
if(multiply == 0)
{
cout<<"I apologize, but you seem to have lost"<<endl;
cout<<"when you lose, your bet is subtracted"<<endl;
cout<<"your initial balance was: "<<tot<<endl;
//decrement the total
tot = (tot - betMonies);
cout<<"your new balance is: "<<tot<<endl;
}//end if
//if multiply is not 0 (assuming it's not negative
//because there's no way it could be)
//we tell them what they've won, and add it to
//their total money
else
{
win = (multiply*betMonies);
cout<<"your initial balance was: "<<tot<<endl;
cout<<"your win was"<<win<<endl;
//increment the total
tot = (win + tot);
cout<<"your new balance is "<<tot<<endl;
}//end else
}//big if end
//if the amount entered was not valid
//simply tell them, then run the loop again
else
{//else begin
cout<<"I'm sorry, that was not a valid amount of money"<<endl;
cout<<"please try again"<<endl;
}//end else
round.shuffleDeck();
return tot;
}//end handlePoker
//handle Black jack:
//a function returning an unsigned int
//that keeps track of the total money
//declares a black jack object
//and uses it's member functions to play black jack
unsigned int handleBlackJack(unsigned int tot)
{
blackJack play;
unsigned int reward;
unsigned int betMoolah;
//ask the user for the bet they want
cout<<"how much do you want to bet?"<<endl;
cin>>betMoolah;
//if the bet is less than the total passed by reference
//then we can start running the game
if(betMoolah < tot)
{
//print the hands dealt in the constructor
play.printHands();
//run the function that lets them hit or stay
//the function contains a do while loop
// so, no looping is required
play.hitOrStay();
//we then handle the reward
//which returns an integer type
reward = play.handleReward(betMoolah);
//prints dealer and player's hands fully
play.printHandGame();
//in one of the cases, reward is set to -1
//we use this here:
if(reward < 0 )
{
//if the reward is negative, then
//we subtract the bet money
//then we tell the user their new balance
cout<<"your balance was "<<tot<<endl;
cout<<"you have lost, so your bet is subtracted"<<endl;
tot = (tot-betMoolah);
cout<<"your new balance is: "<<tot<<endl;
}//end if
//if the reward is above 0, then we add the reward to the total
else if(reward > 0)
{
cout<<"your original balance was "<<tot<<endl;
cout<<"your winnings are: "<< reward<<endl;
tot = reward + tot;
cout<<"your new balance is: "<<tot<<endl;
}//end else
else
{
cout<<"you have lost no money"<<endl;
cout<<"your balance is still " <<tot<<endl;
}
}//end of the big if
//if the amount of money entered is above total money
//then the money entered isn't valid at all
else
{
cout<<"the amount of money you've entered is not valid"<<endl;
cout<<"please try again"<<endl;
}// end else
play.shuffleDeck();
return tot;
}//end handleBlackJack
最佳答案
我无法完全解释您看到的内容,但我确实注意到 unsigned int
的自由使用。特别是,在 handleBlackJack
中,您有:
unsigned int reward;
然后
reward = play.handleReward(betMoolah);
最后
if(reward < 0 )
如果奖励可以是负数,它不应该是一个unsigned int
。正如其他人所建议的那样,在调试器中单步执行它并“关注金钱”。
关于C++数学题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8438351/
我有以下功能: function getLevel(points) { var level = -1 + Math.sqrt(4 + points/20); // Round down to
因此,在我的最终项目(使用从纸牌类继承的二十一点和扑克模拟器)中,我们必须跟踪用户的赌注和总金额。但是,在我的代码中,它做了非常奇怪的事情。例如:如果您的总资金为 1000000000 美元,您下注
我有一个多层视差脚本,目前处于半工作状态。如果假设具有视差效果的元素被放置在网站的顶部,那么效果就在现场工作,因为它滚出 View ,您看不到图层移出框架。 但是我希望能够在整个页面的不同位置的多个元
我正在尝试制作一个转换值的通用方程式。以下是一些示例。 9,873,912 -> 9,900,000 125,930 -> 126,000 2,345 -> 2,400 280 -> 300 28 -
让我首先说明我的数学很糟糕。 我正在尝试重新定位和旋转一个矩形。但是,我需要从一个不是 0,0 的点旋转矩形,而是根据它的坐标移动了多远。我确定这没有多大意义,所以我做了一些草图来帮助解释我需要什么。
我的问题有点难以解释,但我会尽力而为。 我需要一个函数来检查随机坐标是否在“行”中。 一张图片来解释: 假设大小 = 20 且介于 = 100 有无数行。并且坐标始终是 int (大小和之间也是如此)
我正在尝试构建一个“简单”的网络应用程序,根据美国海军的周长公式计算男性或女性的体脂百分比。我已经完成了大部分应用程序。但是,我无法弄清楚为什么我设置下面公式的方式不起作用。在我的 .cs 文件中,其
我将制作一款完全由程序生成的空间/交易/战斗游戏。但是,我知道将整个星系的所有细节存储在内存中是不可行的。因此,我一直认为我可以使用种子来生成太阳系,并且从该太阳系,您可以使用跳跃门前往其他太阳系。问
public int CalcBrackets(int teamCount) { int positions = 1; while (positions > 1
当我用 std::vector 创建一个层时,我计算了我的坐标,填充了 cube 对象(这是我的一个类): for(int J = 0; J < mapSize; J++) { for(int
希望允许它在 stackexchange 站点之间“交叉发布”...有谁知道如何解决以下“数学”问题? https://gamedev.stackexchange.com/questions/5041
这是数学高手的数学/几何问题(不是我最擅长的科目)。这是针对 WPF 的,但应该足够通用以解决问题: 我有两个嵌入的 Border 元素,外部元素具有特定的角半径 R 和边框厚度 T。给定这两个值,内
我是一名优秀的程序员,十分优秀!