我在這裏有一個問題,如果有人可以幫我在這裏,真的很好。這是我第一次使用這個程序,所以不要去評判。基本的C++骰子游戲
#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,即使型投入1或BET2,我不知道如何解決這個問題。然後我的循環功能(int count 0; while(count < 3)count++)
它開始無休止地循環,沒有我按任何東西,即使我在簡單的編碼中使用相同的循環功能,如只需鍵入一些cout < <的東西它的工作正常,但是當我在此代碼中使用它時,流失,有誰知道爲什麼會發生這種情況,如果有人能回答,將感謝,先進的感謝。
如果您將變量重命名爲英文並翻譯註釋會很有幫助 –
在執行程序時只需調用srand()一次。永遠不要把它放在一個循環中。 – drescherjm
無法通過'int bet =(bet1,bet2,bet3)'來猜測你的意思。我建議您再次查看關於變量和賦值的基礎知識。 – molbdnilo