나는 여기에서 문제가있다. 누군가 나를 도와 줄 수 있다면 정말 좋을 것이다. 처음으로이 프로그램을 사용하면 판단력이 떨어집니다. Basic 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");
}
그래서 여기 일이 어떤 이유로 내가 항상 심지어 유형하지만 bet1 또는 bet2에 500을 내기 때문이다, 그리고 어떻게 그 문제를 해결하는 단서가 없다. 그리고 나서 내 루프 함수
(int count 0; while(count < 3)count++)
아무 것도 누르지 않고 끝없이 루프를 시작합니다. 단지 같은 코드를 사용하여 동일한 루프 기능을 사용하더라도 일부 코드를 입력하는 것입니다. < <이 코드에서 사용하면 잘됩니다. 배수구에, 왜 이런 일이 일어나는지, 아무도 대답 할 수 있다면 감사 할 것입니다. 감사합니다.
변수 이름을 영어로 변경하고 번역 된 주석을 –
으로 변경하면 프로그램 실행시 srand()를 한 번만 호출하면 도움이됩니다. 결코 루프에 넣지 마십시오. – drescherjm
'int bet = (bet1, bet2, bet3)'이 무슨 뜻인지 짐작할 수 없습니다. 변수 및 과제에 대한 기본 사항을 다시 검토해 보시기 바랍니다. – molbdnilo