【发布时间】:2013-10-14 00:41:10
【问题描述】:
我在这里遇到问题,如果有人可以在这里帮助我,那就太好了。这是我第一次使用这个程序,所以不要评判。
#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
【问题讨论】:
-
如果您将变量重命名为英文并翻译 cmets 将会很有帮助
-
在程序执行过程中只调用 srand() 1 次。永远不要把它放在一个循环中。
-
不可能猜出
int bet=(bet1, bet2, bet3)的意思。我建议您再次查看有关变量和赋值的基础知识。 -
我建议您调试程序并逐步检查每个部分,以便您更好地理解为什么每个部分没有按照您的想法执行。就目前而言,这有几个问题,对于 SO 来说有点过于宽泛。