找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 1946|回复: 5

刚才编的,找不到错误?

[复制链接]
发表于 2009-11-6 00:40:10 | 显示全部楼层 |阅读模式 IP:江苏扬州
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <fstream>
using namespace std;
//函数的声明
void pick_a_card(int&,int&);
void spin_the_wheel(int&);
void choose_card_or_wheel(int,int&,int&);
void check_the_location(int,int&,int&);
void roll_the_dice(int&);
ofstream outfile("C:\\BDGAME.OUT");
int main()
{
int player1_spot=0,player2_spot=0;
int player,card_number;
srand(time(0));
do
{
outfile<<"\nPlayer 1-Enter 1 toroll the dice."<<endl;
cout<<"\nPlayer 1-Enter 1 toroll the dice."<<endl;
cin>>player;
roll_the_dice(player1_spot);
check_the_location(plyer,player1_spot,card_numb);
if(player1_spot>=90)
break;
outfile<<"\nPlayer 2-Enter 2 toroll the dice."<<endl;
cout<<"\nPlayer 2-Enter 2 toroll the dice."<<endl;
cin>>player;
roll_the_dice(player2_spot);
check_the_location(plyer,player2_spot,card_numb);
}
while(player2_spot<90);
}
void roll_the_dice(int& spot)
{
int roll;
roll=rand()%11+2;
spot+=roll;
outfile<<"you rolled"<<roll<<endl;
cout<<"you rolled"<<roll<<endl;
}
void check_the_location(int player,int& spot,int& card_numb)
{
int choose;
outfile<<"you landed on spot"<<spot<<endl;
cout<<"you landed on spot"<<spot<<endl;
if(spot==30)
{
outfile<<"you get the shortcut to 70."<<endl;
cout<<"you get the shortcut to 70."<<endl;
spot=70;
}
if(spot==10||spot==60)
{
pick_a_card(spot,card_numb);
}
else if(spot==40||spot==70)
{
spin_the_wheel(spot);
}
else if(spot==80)
{
choose_card_or_wheel(spot,card_number);
}
else if(spot>=90)
{
outfile<<"Player"<<player<<"wins!"<<endl;
cout<<"Player"<<player<<"wins!"<<endl;
}
else
{
outfile<<"Keep playing!"<<endl;
cout<<"Keep playing!"<<endl;
}
return;
}
void choose_card_or_wheel(int& spot,int& card_number)
{
int choice;
outfile<<"enter 1 to spin the wheel or 2 to pick a card."<<endl;
cout<<"enter 1 to spin the wheel or 2 to pick a card."<<endl;
if(choice==1)
{
spin_the_wheel(spot);
}
else
{
pick_a_card(spot,card_number);
}
return;
}
void spin_the_wheel(int& spot)
{
int spin;
outfile<<"you get to spin the wheel!"<<endl;
cout<<"you get to spin the wheel!"<<endl;
spin=rand()%8+1;
if(spin==1)
{
spot-=4;
outfile<<"go back 4.you are at spot"<<spot<<endl;
cout<<"go back 4.you are at spot"<<spot<<endl;
}
else if(spin==2)
{
spot+=2;
outfile<<"go forward 2.you are at spot"<<spot<<endl;
cout<<"go forward 2.you are at spot"<<spot<<endl;
}
else if(spin==3)
{
spot-=6;
outfile<<"go back 6.you are at spot"<<spot<<endl;
cout<<"go back 6.you are at spot"<<spot<<endl;
}
else if(spin==4)
{
spot-=9;
outfile<<"go back 9.you are at spot"<<spot<<endl;
cout<<"go back 9.you are at spot"<<spot<<endl;
}
else if(spin==5)
{
spot=0;
outfile<<"go back to the beginning.you are at spot"<<spot<<endl;
cout<<"go back to the beginning.you are at spot"<<spot<<endl;
}
else if(spin==6)
{
spot-=8;
outfile<<"go back 8.you are at spot"<<spot<<endl;
cout<<"go back 8.you are at spot"<<spot<<endl;
}
else if(spin==7)
{
spot-=7;
outfile<<"go back 7.you are at spot"<<spot<<endl;
cout<<"go back 7.you are at spot"<<spot<<endl;
}
else
{
spot+=1;
outfile<<"go forward 1.you are at spot."<<spot<<endl;
cout<<"go forward 1.you are at spot."<<spot<<endl;
}
return;
}
void pick_a_card(int& spot,int& card_number)
{
outfile<<"you get to pick a card!"<<endl;
cout<<"you get to pick a card!"<<endl;
card_numb++;
if(card_num==11)
card_num=1;
if(card_num==1)
{
spot-=9;
outfile<<"go back 9.you are at spot"<<spot<<endl;
cout<<"go back 9.you are at spot"<<spot<<endl;
}
else if(card_num==2)
{
spot=0;
outfile<<"go back to the beginning.you are at spot"<<spot<<endl;
cout<<"go back to the beginning.you are at spot"<<spot<<endl;
}
else if(card_num==3)
{
spot-=3;
outfile<<"go back 3.you are at spot"<<spot<<endl;
cout<<"go back 3.you are at spot"<<spot<<endl;
}
else if(card_num==4)
{
spot-=8;
outfile<<"go back 8.you are at spot"<<spot<<endl;
cout<<"go back 8.you are at spot"<<spot<<endl;
}
else if(card_num==5)
{
spot+=2;
outfile<<"go forward 2.you are at spot."<<spot<<endl;
cout<<"go forward 2.you are at spot."<<spot<<endl;
}
else if(card_num==6)
{
spot-=8;
outfile<<"go back 8.you are at spot."<<spot<<endl;
cout<<"go back 8.you are at spot."<<spot<<endl;
}
else if(card_num==7)
{
spot+=1;
outfile<<"go forward 1.you are at spot."<<spot<<endl;
cout<<"go forward 1.you are at spot."<<spot<<endl;
}
else if(card_num==8)
{
spot+=1;
outfile<<"go forward 3.you are at spot."<<spot<<endl;
cout<<"go forward 3.you are at spot."<<spot<<endl;
}
else if(card_num==9)
{
spot=0;
outfile<<"go back to the beginning.you are at spot"<<spot<<endl;
cout<<"go back to the beginning.you are at spot"<<spot<<endl;
}
else if(card_num==10)
{
spot-=4;
outfile<<"go back 4.you are at spot."<<spot<<endl;
cout<<"go back 4.you are at spot."<<spot<<endl;
}
else
{
spot+=6;
outfile<<"go forward 6.you are at spot."<<spot<<endl;
cout<<"go forward 6.you are at spot."<<spot<<endl;
}
return;
}
Compiling...
1-1.cpp
C:\Documents and Settings\Administrator\桌面\1-1.cpp(27) : error C2065: 'plyer' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\1-1.cpp(27) : error C2065: 'card_numb' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\1-1.cpp(38) : warning C4508: 'main' : function should return a value; 'void' return type assumed
C:\Documents and Settings\Administrator\桌面\1-1.cpp(70) : error C2660: 'choose_card_or_wheel' : function does not take 2 parameters
C:\Documents and Settings\Administrator\桌面\1-1.cpp(166) : error C2065: 'card_num' : undeclared identifier
执行 cl.exe 时出错.
1-1.obj - 1 error(s), 0 warning(s)
我老是看不懂错误的提示,改不了啊.
发表于 2009-11-6 00:40:11 | 显示全部楼层 IP:江苏扬州
'plyer' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\1-1.cpp(27) : error C2065: 'card_numb'

'card_num'
这是拼错了.
main函数忘写返回值.
void choose_card_or_wheel(int,int&,int&);//三个参数.
回复

使用道具 举报

发表于 2009-11-6 00:40:13 | 显示全部楼层 IP:江苏扬州
要细心啊,怎么会检查不出来呢!!!
回复

使用道具 举报

发表于 2009-11-6 00:40:14 | 显示全部楼层 IP:江苏扬州
恩,就是,要特别细心,现在终于找到错误啦.
回复

使用道具 举报

发表于 2009-11-6 00:40:17 | 显示全部楼层 IP:江苏扬州
改错后:

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <fstream>
using namespace std;
//函数的声明
void pick_a_card(int&,int&);
void spin_the_wheel(int&);
void choose_card_or_wheel(int&,int&);
void check_the_location(int,int&,int&);
void roll_the_dice(int&);
ofstream outfile("C:\\BDGAME.OUT");
void main()
{
int player1_spot=0,player2_spot=0;
int player,card_num;
srand(time(0));
do
{
outfile<<"\nPlayer 1-Enter 1 toroll the dice."<<endl;
cout<<"\nPlayer 1-Enter 1 toroll the dice."<<endl;
cin>>player;
roll_the_dice(player1_spot);
check_the_location(player,player1_spot,card_num);
if(player1_spot>=90)
break;
outfile<<"\nPlayer 2-Enter 2 toroll the dice."<<endl;
cout<<"\nPlayer 2-Enter 2 toroll the dice."<<endl;
cin>>player;
roll_the_dice(player2_spot);
check_the_location(player,player2_spot,card_num);
}
while(player2_spot<90);
}
void roll_the_dice(int& spot)
{
int roll;
roll=rand()%11+2;
spot+=roll;
outfile<<"you rolled"<<roll<<endl;
cout<<"you rolled"<<roll<<endl;
}
void check_the_location(int player,int& spot,int& card_num)
{
int choose;
outfile<<"you landed on spot"<<spot<<endl;
cout<<"you landed on spot"<<spot<<endl;
if(spot==30)
{
outfile<<"you get the shortcut to 70."<<endl;
cout<<"you get the shortcut to 70."<<endl;
spot=70;
}
if(spot==10||spot==60)
{
pick_a_card(spot,card_num);
}
else if(spot==40||spot==70)
{
spin_the_wheel(spot);
}
else if(spot==80)
{
choose_card_or_wheel(spot,card_num);
}
else if(spot>=90)
{
outfile<<"Player"<<player<<"wins!"<<endl;
cout<<"Player"<<player<<"wins!"<<endl;
}
else
{
outfile<<"Keep playing!"<<endl;
cout<<"Keep playing!"<<endl;
}
return;
}
void choose_card_or_wheel(int& spot,int& card_num)
{
int choice;
outfile<<"enter 1 to spin the wheel or 2 to pick a card."<<endl;
cout<<"enter 1 to spin the wheel or 2 to pick a card."<<endl;
if(choice==1)
{
spin_the_wheel(spot);
}
else
{
pick_a_card(spot,card_num);
}
return;
}
void spin_the_wheel(int& spot)
{
int spin;
outfile<<"you get to spin the wheel!"<<endl;
cout<<"you get to spin the wheel!"<<endl;
spin=rand()%8+1;
if(spin==1)
{
spot-=4;
outfile<<"go back 4.you are at spot"<<spot<<endl;
cout<<"go back 4.you are at spot"<<spot<<endl;
}
else if(spin==2)
{
spot+=2;
outfile<<"go forward 2.you are at spot"<<spot<<endl;
cout<<"go forward 2.you are at spot"<<spot<<endl;
}
else if(spin==3)
{
spot-=6;
outfile<<"go back 6.you are at spot"<<spot<<endl;
cout<<"go back 6.you are at spot"<<spot<<endl;
}
else if(spin==4)
{
spot-=9;
outfile<<"go back 9.you are at spot"<<spot<<endl;
cout<<"go back 9.you are at spot"<<spot<<endl;
}
else if(spin==5)
{
spot=0;
outfile<<"go back to the beginning.you are at spot"<<spot<<endl;
cout<<"go back to the beginning.you are at spot"<<spot<<endl;
}
else if(spin==6)
{
spot-=8;
outfile<<"go back 8.you are at spot"<<spot<<endl;
cout<<"go back 8.you are at spot"<<spot<<endl;
}
else if(spin==7)
{
spot-=7;
outfile<<"go back 7.you are at spot"<<spot<<endl;
cout<<"go back 7.you are at spot"<<spot<<endl;
}
else
{
spot+=1;
outfile<<"go forward 1.you are at spot."<<spot<<endl;
cout<<"go forward 1.you are at spot."<<spot<<endl;
}
return;
}
void pick_a_card(int& spot,int& card_num)
{
outfile<<"you get to pick a card!"<<endl;
cout<<"you get to pick a card!"<<endl;
card_num++;
if(card_num==11)
card_num=1;
if(card_num==1)
{
spot-=9;
outfile<<"go back 9.you are at spot"<<spot<<endl;
cout<<"go back 9.you are at spot"<<spot<<endl;
}
else if(card_num==2)
{
spot=0;
outfile<<"go back to the beginning.you are at spot"<<spot<<endl;
cout<<"go back to the beginning.you are at spot"<<spot<<endl;
}
else if(card_num==3)
{
spot-=3;
outfile<<"go back 3.you are at spot"<<spot<<endl;
cout<<"go back 3.you are at spot"<<spot<<endl;
}
else if(card_num==4)
{
spot-=8;
outfile<<"go back 8.you are at spot"<<spot<<endl;
cout<<"go back 8.you are at spot"<<spot<<endl;
}
else if(card_num==5)
{
spot+=2;
outfile<<"go forward 2.you are at spot."<<spot<<endl;
cout<<"go forward 2.you are at spot."<<spot<<endl;
}
else if(card_num==6)
{
spot-=8;
outfile<<"go back 8.you are at spot."<<spot<<endl;
cout<<"go back 8.you are at spot."<<spot<<endl;
}
else if(card_num==7)
{
spot+=1;
outfile<<"go forward 1.you are at spot."<<spot<<endl;
cout<<"go forward 1.you are at spot."<<spot<<endl;
}
else if(card_num==8)
{
spot+=1;
outfile<<"go forward 3.you are at spot."<<spot<<endl;
cout<<"go forward 3.you are at spot."<<spot<<endl;
}
else if(card_num==9)
{
spot=0;
outfile<<"go back to the beginning.you are at spot"<<spot<<endl;
cout<<"go back to the beginning.you are at spot"<<spot<<endl;
}
else if(card_num==10)
{
spot-=4;
outfile<<"go back 4.you are at spot."<<spot<<endl;
cout<<"go back 4.you are at spot."<<spot<<endl;
}
else
{
spot+=6;
outfile<<"go forward 6.you are at spot."<<spot<<endl;
cout<<"go forward 6.you are at spot."<<spot<<endl;
}
return;
}
回复

使用道具 举报

发表于 2009-11-6 00:40:19 | 显示全部楼层 IP:江苏扬州
知”错“能改,善莫大焉
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-10-1 12:11 , Processed in 0.185394 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表