基本C ++骰子游戏 [英] Basic C++ Dice game
问题描述
我在这里有一个问题,如果任何人可以帮助我在这里真的很好。它是我第一次使用这个程序,所以不要判断。
I have a problem here, would be really nice if anyone could help me out here. Its my first time using this program so dont be to judgemental.
#include <cstdlib>
#include <iostream>
using namespace std;
int throw1, throw2, throw3, throw4;
int bet1 = 100;
int bet2 = 300;
int bet3 = 500;
int bet=(bet1, bet2, bet3);
int deposit;
int account;
int main(){
int count = 0;
while(count < 3){
cin>>deposit;
while(deposit>5000 || deposit<0){ //Makes sure so that my deposit is between 0-5000
cout<<"deposit failed"<<endl;
cin>>deposit;
}
account = deposit;
cout<<"You have deposited" <<deposit<<"Swedish Krona"<<endl;
cout<<"and you have this much cash on your account"<<account<<"Swedish Krona"<<endl;
if (konto>499){ //Makes sure so that i have the money to bet, and if i dont have the money, i can just put in more
cout<<"please place your bet"<<endl;
cout<<"bet1=100, bet2=300, bet3=500"<<endl;
cin>>bet1;
cin>>bet2;
cin>>bet3;
account = (deposit - bet);
cout<<"you have this much cash on your account"<<account<<"Swedish Krona"<<endl;
}
else if(account>299){
cout<<"please place your bet"<<endl;
cout<<"bet1=100, bet=300"<<endl;
cin>>bet1;
cin>>bet2;
account =(deposit - bet);
cout<<"you have this much cash on your account"<<account<<"Swedish Krona"<<endl;
}
else if(account>99){
cout<<"please place your bet"<<endl;
cout<<"bet1=100"<<endl;
cin>>bet1;
cout<<"you have placed your bet"<<bet<<"Swedish Krona"<<endl;
}
while (account<100 || deposit>5000){
cout<<"insufficient funds"<<endl;
cin>>deposit;
account=deposit;
}
{
cout<<"Throw dice"<<endl;
srand(time(0));
Throw1 = rand() % 6 + 1;
Throw2 = rand() % 6 + 1;
Throw3 = rand() % 6 + 1;
Throw4 = rand() % 6 + 1;
cout<<"You rolled"<<Throw1<<endl;
cout<<"You rolled"<<Throw2<<endl;
cout<<"Computer rolled"<<Throw3<<endl;
cout<<"Computer rolled"<<Throw4<<endl;
}
}
count++;
system ("pause");
}
所以这里的东西是,由于某种原因,我总是下注500,甚至虽然输入bet1或bet2,我不知道如何解决这个问题。然后我的循环函数(int count 0; while(count< 3)count ++)
它开始循环无限循环,没有我按任何东西,即使我使用相同的循环函数在简单的编码中只需键入一些cout<事情它工作正常,但是当我使用它在这段代码,它去排水,任何人知道为什么这是发生,将欣赏,如果任何人可以回答,感谢先进。
So the thing here is that, for some reason i always bet 500, even though type in bet1 or bet2, and i have no clue how to fix that problem. And then my loop function (int count 0; while(count < 3)count++)
it starts to loop endlessly without me pressing anything, even though i use the same loop function in simple coding like just typing some cout<< things it works fine, but when i use it in this code, it goes to drain, do anyone know why this is happening, would appreciate if anyone could answer, thanks in advanced.
推荐答案
int bet1 = 100;
int bet2 = 300;
int bet3 = 500;
int bet=(bet1, bet2, bet3)
最后一行将被评估为这个:100,300,500.逗号分隔的表达式列表的结果将是最后一个值,这是500.所以你的下注变量将始终设置为500.
The last line will be evaluated like this: 100, 300, 500. Result of comma separated list of expression will be last value, which is 500. So your bet variable will be always set to 500.
这篇关于基本C ++骰子游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!