| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 598 人关注过本帖
标题:刚才编的,找不到错误?
只看楼主 加入收藏
兜兜里有枪
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-4-22
收藏
 问题点数:0 回复次数:5 
刚才编的,找不到错误?

#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)
我老是看不懂错误的提示,改不了啊.

搜索更多相关主题的帖子: int void include card 
2007-05-02 16:34
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 

'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&);//三个参数.


倚天照海花无数,流水高山心自知。
2007-05-02 19:18
aipb2007
Rank: 8Rank: 8
来 自:CQU
等 级:贵宾
威 望:40
帖 子:2879
专家分:7
注 册:2007-3-18
收藏
得分:0 
要细心啊,怎么会检查不出来呢!!!

Fight  to win  or  die...
2007-05-02 22:46
兜兜里有枪
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-4-22
收藏
得分:0 
恩,就是,要特别细心,现在终于找到错误啦.
2007-05-03 10:55
兜兜里有枪
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-4-22
收藏
得分:0 

改错后:

#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;
}

2007-05-03 10:56
yuyunliuhen
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:1435
专家分:0
注 册:2005-12-12
收藏
得分:0 

知”错“能改,善莫大焉


Go confidently in the  directions of your dreams,live the life you have imagined!Just do it!
It is no use learning without thinking!
2007-05-03 13:17
快速回复:刚才编的,找不到错误?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029249 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved