我这程序怎么还是没法运行

sunsold 2009-03-31 11:03:55
把这个程序改了 可是怎么还是没法运行
而且让电脑代替人模拟10000次并且记录change和不change的获胜次数我也不会!!!!!!!急啊

#include <iostream>
#include <cstdlib>
#include <time.h>

using namespace std;

int select,door;

void main()
{

door=rand()%3+1;
cout <<"you can choose one door of the three" <<endl;
cin>>select;
if(select==door)
void same();
else
void different();

}

void same()
{
int select1;

switch(select1)
case 1:
cout<<"The door2 has a consolation prize.Do you want to change your select"<<endl;
case 2:
cout<<"The door1 has a consolation prize.Do you want to change your select"<<endl;
case 3:
cout<<"The door2 has a consolation prize.Do you want to change your select"<<endl;

cout<<"please select again: door1 door2 door3"<<endl;
cin>>select1;

if(select1==door)
cout<<"You win the game"<<endl;
else
cout<<"You lose"<<endl;
}
void different()
{
int select2;

switch(select2)
case select==1,door==2:
cout<<"The door3 has a consolation prize.Do you want to change your select"<<endl;
case select==2,door==1:
cout<<"The door3 has a consolation prize.Do you want to change your select"<<endl;
case select==3,door==1:
cout<<"The door2 has a consolation prize.Do you want to change your select"<<endl;
case select==1,door==3:
cout<<"The door2 has a consolation prize.Do you want to change your select"<<endl;
case select==2,door==3:
cout<<"The door1 has a consolation prize.Do you want to change your select"<<endl;
case select==3,door==2:
cout<<"The door1 has a consolation prize.Do you want to change your select"<<endl;


cout<<"please select again: door1 door2 door3"<<endl;
cin>>select2;

if(select2==door)
cout<<"You win the game"<<endl;
else
cout<<"You lose"<<endl;
}
...全文
105 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunsold 2009-03-31
  • 打赏
  • 举报
回复
#include <iostream>
#include <cstdlib>
#include <time.h>

using namespace std;

int select,door;

void main()
{

door=rand()%3+1;
cout <<"you can choose one door of the three" <<endl;
cin>>select;
if(select==door)
void same();
else
void different();

}

void same()
{
int select1;

if(select==1)
cout<<"The door2 has a consolation prize.Do you want to change your select"<<endl;
else if(select==2)
cout<<"The door1 has a consolation prize.Do you want to change your select"<<endl;
else if(select==3)
cout<<"The door2 has a consolation prize.Do you want to change your select"<<endl;

cout<<"please select again: door1 door2 door3"<<endl;
cin>>select1;

if(select1==door)
cout<<"You win the game"<<endl;
else
cout<<"You lose"<<endl;
}
void different()
{
int select2;


if(select==1&&door==2)
cout<<"The door3 has a consolation prize.Do you want to change your select"<<endl;
else if ( select==2&&door==1)
cout<<"The door3 has a consolation prize.Do you want to change your select"<<endl;
else if ( select==3&&door==1)
cout<<"The door2 has a consolation prize.Do you want to change your select"<<endl;
else if (select==1&&door==3)
cout<<"The door2 has a consolation prize.Do you want to change your select"<<endl;
else if ( select==2&&door==3)
cout<<"The door1 has a consolation prize.Do you want to change your select"<<endl;
else if ( select==3&&door==2)
cout<<"The door1 has a consolation prize.Do you want to change your select"<<endl;

cout<<"please select again: door1 door2 door3"<<endl;
cin>>select2;

if(select2==door)
cout<<"You win the game"<<endl;
else
cout<<"You lose"<<endl;
}

sunsold 2009-03-31
  • 打赏
  • 举报
回复
if(select==1)
cout<<"The door2 has a consolation prize.Do you want to change your select"<<endl;
else if(select==2)
cout<<"The door1 has a consolation prize.Do you want to change your select"<<endl;
else if(select==3)
cout<<"The door2 has a consolation prize.Do you want to change your select"<<endl;

cout<<"please select again: door1 door2 door3"<<endl;
cin>>select1;

if(select1==door)
cout<<"You win the game"<<endl;
else
cout<<"You lose"<<endl;
sunsold 2009-03-31
  • 打赏
  • 举报
回复
改了一下 能运行了 但是为什么 不执行函数的????????????????????????

#include <iostream>
#include <cstdlib>
#include <time.h>

using namespace std;

int select,door;

void main()
{

door=rand()%3+1;
cout <<"you can choose one door of the three" <<endl;
cin>>select;
if(select==door)
void same();
else
void different();

}

void same()
{
int select1;

if(select==1)
cout<<"The door2 has a consolation prize.Do you want to change your select"<<endl;
else if(select==2)
cout<<"The door1 has a consolation prize.Do you want to change your select"<<endl;
else if(select==3)
cout<<"The door2 has a consolation prize.Do you want to change your select"<<endl;

cout<<"please select again: door1 door2 door3"<<endl;
cin>>select1;

if(select1==door)
cout<<"You win the game"<<endl;
else
cout<<"You lose"<<endl;
}
void different()
{
int select2;


if(select==1&&door==2)
cout<<"The door3 has a consolation prize.Do you want to change your select"<<endl;
else if ( select==2&&door==1)
cout<<"The door3 has a consolation prize.Do you want to change your select"<<endl;
else if ( select==3&&door==1)
cout<<"The door2 has a consolation prize.Do you want to change your select"<<endl;
else if (select==1&&door==3)
cout<<"The door2 has a consolation prize.Do you want to change your select"<<endl;
else if ( select==2&&door==3)
cout<<"The door1 has a consolation prize.Do you want to change your select"<<endl;
else if ( select==3&&door==2)
cout<<"The door1 has a consolation prize.Do you want to change your select"<<endl;

cout<<"please select again: door1 door2 door3"<<endl;
cin>>select2;

if(select2==door)
cout<<"You win the game"<<endl;
else
cout<<"You lose"<<endl;
}
lingyin55 2009-03-31
  • 打赏
  • 举报
回复
void different()
{
int select2; //这个也一样

switch(select2)


你应该定义函数的入参,比如

void same( int i )
{
int select1 = i;
//下面是你的程序
}

void different( int i )
{
//同上
}


//主函数调用
main()
{
//....
same(select);
//....
different(select);
}
//另外你定义的变量door也是没有初始化,而且看似没有什么作用。程序很乱,自己再整理吧
lingyin55 2009-03-31
  • 打赏
  • 举报
回复
void same()
{
int select1; //这里都没有初始化,怎么用switch判断啊??

switch(select1)

65,211

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧