モンティホールを作ってるのですが助けてください

ティキタカ
記事: 20
登録日時: 10年前

モンティホールを作ってるのですが助けてください

投稿記事 by ティキタカ » 10年前

最初のユーザーの選択と選択肢を外すためのところと、最後の選択肢が一緒になったりしてごちゃごちゃになってしまうのですが、どうすればよろしいでしょうか。


using namespace std;
int computerrandom();
int firstgoat();
int secondgoat();
void printMessage();
void saisyo(int&);
void erabukesu(unsigned int, int, unsigned int,unsigned int);
void kesu(int,unsigned int);
void kekka(unsigned int, int,unsigned int, int&);
int main()
{
printMessage();
int choice;
saisyo(choice);
if (choice>3||choice>firstChoice;
}
int firstgoat()
{
unsigned int goat1;
srand(unsigned(time(0)));//set the time
goat1=(rand()%3)+1;
return goat1;
}
int secondgoat()
{
unsigned int goat2;
srand(unsigned(time(0)));//set the time
goat2=(rand()%3)+1;
return goat2;
}
void printMessage()//the first message
{
cout>secondChoice;
switch(secondChoice)
{
case 1:
if(firstChoice==secondChoice)
{
if(secondChoice==car)
{
cout<<"You decide not to change your mind"<<endl;
cout<<"You have won CAR"<<endl;
}
else if(secondChoice!=car)
{
cout<<"You decide not to change your mind"<<endl;
cout<<"You have won A GOAT"<<endl;
}
}
break;
case 2:
if (firstChoice!=secondChoice)
{
if(secondChoice==car)
{
cout<<"You decide to change your mind"<<endl;
cout<<"You have won CAR"<<endl;
}
else if(secondChoice!=car)
{
cout<<"You decide tochange your mind"<<endl;
cout<<"You have won A GOAT"<<endl;
}
}
break;
default:
cout<<" You choose invalid box number./n Please try again:"<<endl;
}
}

アバター
みけCAT
記事: 6734
登録日時: 14年前

RE: モンティホールを作ってるのですが助けてください

投稿記事 by みけCAT » 10年前

  • 「本格的」な質問は日記ではなく、質問掲示板でする
  • コードを投稿するときは、BBcodeを有効にした状態でcodeタグで囲む
  • インデントを整える
  • 必要な#includeディレクティブをきちんと書く
  • 無駄にsrandを呼ばない
  • 抽選関数(computerrandom, firstgoat, secondgoat)を無駄に呼ばない
  • erabukesu関数での調整結果があとの処理に反映されるようにする
  • erabukesu関数で不正な抽選結果を弾くようにする
  • kekka関数で必ず結果が表示されるようにする

CODE:

#include 
#include 
#include 

using namespace std;
int computerrandom();
int firstgoat();
int secondgoat();
void printMessage();
void saisyo(int&);
void erabukesu(int, int, int&,int&);
void kesu(int,int);
void kekka(int, int,int, int&);
int main()
{
	srand(unsigned(time(NULL)));
	printMessage();
	int choice;
	int computerrandamu;
	int firstgooto;
	int secondgooto;
	saisyo(choice);
	if (choice>3||choice>firstChoice;
}
int firstgoat()
{
	int goat1;
	goat1=(rand()%3)+1;
	return goat1;
}
int secondgoat()
{
	int goat2;
	goat2=(rand()%3)+1;
	return goat2;
}
void printMessage()//the first message
{
	cout>secondChoice;
	//TODO: do refactor
	switch(secondChoice)
	{
		case 1:
			if(firstChoice==secondChoice)
			{
				if(secondChoice==car)
				{
					cout<<"You decide not to change your mind"<<endl;
					cout<<"You have won CAR"<<endl;
				}
				else if(secondChoice!=car)
				{
					cout<<"You decide not to change your mind"<<endl;
					cout<<"You have won A GOAT"<<endl;
				}
			}
			else
			{
				if(firstChoice==car)
				{
					cout<<"You decide not to change your mind"<<endl;
					cout<<"You have won CAR"<<endl;
				}
				else if(firstChoice!=car)
				{
					cout<<"You decide not to change your mind"<<endl;
					cout<<"You have won A GOAT"<<endl;
				}
			}
			break;
		case 2:
			if (thelastbox!=secondChoice)
			{
				if(thelastbox==car)
				{
					cout<<"You decide to change your mind"<<endl;
					cout<<"You have won CAR"<<endl;
				}
				else if(thelastbox!=car)
				{
					cout<<"You decide tochange your mind"<<endl;
					cout<<"You have won A GOAT"<<endl;
				}
			}
			else
			{
				if(secondChoice==car)
				{
					cout<<"You decide to change your mind"<<endl;
					cout<<"You have won CAR"<<endl;
				}
				else if(secondChoice!=car)
				{
					cout<<"You decide tochange your mind"<<endl;
					cout<<"You have won A GOAT"<<endl;
				}
			}
			break;
		default:
			cout<<" You choose invalid box number./n Please try again:"<<endl;
	}
}
最後に編集したユーザー みけCAT on 2015年4月11日(土) 09:05 [ 編集 1 回目 ]
理由: デバッグ出力が残っていたので削除

ティキタカ
記事: 20
登録日時: 10年前

Re: モンティホールを作ってるのですが助けてください

投稿記事 by ティキタカ » 10年前

ルールを知らずに勝手な事をして申し訳ございません。
そしてありがとうございます。
ルールをしっかりと守るので、これからもよろしくお願いします。