各位大侠 救救我啊!!! 编译出来26个错误!我的汗啊

ChargeForward 2008-04-17 09:49:52
这是一个猜单词的游戏,我第一次编写大一点的C++ 怎么会这样啊 各位前辈高手帮我看下 谢谢啦!!!
#include<iostream>
#include<string>
#include<cctype>
#include<cstdlib>
main()
{
int i;
int chance=10;
int rigth=0;
string word="hello";
string temp;
char letter;
temp=word;
for(i=0;i<word.length();i++)
{temp.replace(i,1,1,'*');}
do{
cout<<"Please enter a letter:"<<endl<<endl<<chance<<"chance left"<<endl;
cin>>letter;
chance--;
for(i=0;i<temp.length();i++)
{while(!isalpha(letter)&&chance>0){
Flush(cin);
cout<<"Not a letter,please enter a letter!"<<endl<<endl<<chance<<"chance left"<<endl;
cin>>letter;
chance--;
if(letter==temp.at()&&chance>0)
{cout<<endl;
cout<<"This letter have been chosen.Please enter an unchosen letter"<<endl<<endl<<endl<<chance<<"chance left"<<endl;
cin=letter;
chance--;
i=-1;
}
}
}
for(i=0;i<word.length();i++)
{
if(letter==word.at(i)&&chance>0)
{temp.replace(i,1,1,letter);
rigth++;
if(rigth==word.length())
{cout<<"You get it!"<<"["<<word<<"]"<<endl;
break;
}
}
else{
if(chance>0)
cout<<"Wrong letter!"<<endl;
}
}
}while(rigth<word.length()&&chance>0)
cout<<"You lose it!"<<"["<<word<<"]"<<endl;
}
...全文
114 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
luozhi9 2008-04-18
  • 打赏
  • 举报
回复
围观一下了
独孤过儿 2008-04-18
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 qmm161 的回复:]
我敢说ls这些人都是冲着lz的头像去的....
[/Quote]
为了避嫌,我只能围观一下了,谁让我是君子呢...
yanfeilin 2008-04-18
  • 打赏
  • 举报
回复
为哈不能用namespace?
sun420 2008-04-18
  • 打赏
  • 举报
回复

#include <iostream>
#include <string>
#include <cctype>
#include <cstdlib>
using namespace std;
int main()
{
int i;
int chance=10;
int rigth=0;
string word="hello";
string temp;
char letter;
temp=word;
for(i=0;i <word.length();i++)
{
temp.replace(i,1,1,'*');
}
do
{
cout <<"Please enter a letter:" <<endl <<endl <<chance <<"chance left" <<endl;
cin>>letter;
chance--;
for(i=0;i <temp.length();i++)
{
while(!isalpha(letter)&&chance>0)
{
fflush(stdin);
cout <<"Not a letter,please enter a letter!" <<endl<<endl<<chance <<"chance left" <<endl;
cin>>letter;
chance--;
if(letter==temp.at(0)&&chance>0)
{
cout <<endl;
cout <<"This letter have been chosen.Please enter an unchosen letter" <<endl <<endl <<endl <<chance <<"chance left" <<endl;
cin>>letter;
chance--;
i=-1;
}
}
}
for(i=0;i <word.length();i++)
{
if(letter==word.at(i)&&chance>0)
{
temp.replace(i,1,1,letter);
rigth++;
if(rigth==word.length())
{
cout <<"You get it!" <<"[" <<word <<"]" <<endl;
break;
}
}
else
{
if(chance>0)
cout <<"Wrong letter!" <<endl;
}
}
}
while(rigth <word.length()&&chance>0);
cout <<"You lose it!" <<"[" <<word <<"]" <<endl;
return 0;
}



能运行 不过不知道结果应该怎么样,也许有逻辑错误 LZ自己在看看哈
loseblue 2008-04-18
  • 打赏
  • 举报
回复
我也换一个吧~
sun420 2008-04-18
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 qmm161 的回复:]
我敢说ls这些人都是冲着lz的头像去的....
[/Quote]
哈哈 我是楼下的
qmm161 2008-04-18
  • 打赏
  • 举报
回复
我敢说ls这些人都是冲着lz的头像去的....
ChargeForward 2008-04-18
  • 打赏
  • 举报
回复
15楼的逻辑非常巧妙啊 不过 WORD在那个大的程序里不是定值 不能确定里面有多少个字母 所以TEMP转换 得改
我是风 2008-04-18
  • 打赏
  • 举报
回复
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
const int chance = 10;
const string word("hello");
const unsigned loops = word.length();
string temp("*****");
unsigned right = 0;
char letter;

for(int i = chance; i > 0; i--)
{
cout << "Please enter a letter(" << i << " chance left):" << endl;
cin >> letter;
for(unsigned j = 0; j < loops; j++)
{
if((letter == word.at(j)) && letter != temp.at(j))
{
temp[j] = letter;
right++;
break;
}
}
cout << "Result:" << temp << endl;
if(right == loops)
{
cout << "U r right!" << endl;
break;
}
}
if(right != loops)
cout << "U r wrong!" << endl;

return 0;
}
ChargeForward 2008-04-17
  • 打赏
  • 举报
回复
不是不能运行 我前一次下载的VC++不好用 我想换一个 正在下载呢
PcrazyC 2008-04-17
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 ChargeForward 的回复:]
4楼的大侠 你改的程序可以运行吗?
[/Quote]

?你那边不能运行?
我运行很好啊


Please enter a letter:

10chance left
34
Not a letter,please enter a letter!

9chance left
54
Not a letter,please enter a letter!

8chance left
34
Not a letter,please enter a letter!

7chance left
65
Not a letter,please enter a letter!

6chance left
..........
ChargeForward 2008-04-17
  • 打赏
  • 举报
回复
4楼的大侠 你改的程序可以运行吗?
PcrazyC 2008-04-17
  • 打赏
  • 举报
回复
不用命名空间那就很多要加std::了,太麻烦


#include <iostream> 
#include <string>
#include <cctype>
#include <cstdlib>
using namespace std;

int main()
{
int i;
int chance=10;
int rigth=0;
string word="hello";
string temp;
char letter;
temp=word;
for(i=0;i <word.length();i++) {
temp.replace(i,1,1,'*');
}
do{
cout <<"Please enter a letter:" <<endl <<endl <<chance <<"chance left" <<endl;
cin>>letter;
chance--;
for(i=0;i <temp.length();i++){
while(!isalpha(letter)&&chance>0){
fflush(stdin);
cout <<"Not a letter,please enter a letter!" <<endl <<endl <<chance <<"chance left" <<endl;
cin>>letter;
chance--;

if(letter==temp.at(i)&&chance>0){
cout <<endl;
cout <<"This letter have been chosen.Please enter an unchosen letter" <<endl <<endl <<endl <<chance <<"chance left" <<endl;
cin>>letter;
chance--;
i=-1;
}
}
}

for(i=0;i <word.length();i++) {
if(letter==word.at(i)&&chance>0){
temp.replace(i,1,1,letter);
rigth++;
if(rigth==word.length()) {
cout <<"You get it!" <<"[" <<word <<"]" <<endl;
break;
}
}
else{
if(chance>0)
cout <<"Wrong letter!" <<endl;
}
}
}while(rigth <word.length()&&chance>0);
cout <<"You lose it!" <<"[" <<word <<"]" <<endl;
return 0;
}
ChargeForward 2008-04-17
  • 打赏
  • 举报
回复
忘了说了 不允许使用命名空间。。。 不过还是谢谢你哈
wuyu637 2008-04-17
  • 打赏
  • 举报
回复
很多基本的格式错误,,

自己认真改一改。。:)


// test.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"

#include <iostream>
#include <vector>
#include <cctype>
using namespace std;
#include <iostream>
#include <string>
#include <cctype>
#include <cstdlib>
void main()
{
int i;
int chance=10;
int rigth=0;
string word="hello";
string temp;
char letter;
temp=word;
for(i=0;i <word.length();i++)
{temp.replace(i,1,1,'*');}


do{
cout <<"Please enter a letter:" <<endl <<endl <<chance <<"chance left" <<endl;
cin>>letter;
chance--;
for(i=0;i <temp.length();i++)
{
while(!isalpha(letter)&&chance>0)
{
fflush(stdin);
cout <<"Not a letter,please enter a letter!" <<endl <<endl <<chance <<"chance left" <<endl;
cin>>letter;
chance--;
if(letter==temp.at(i)&&chance>0)
{cout <<endl;
cout <<"This letter have been chosen.Please enter an unchosen letter" <<endl <<endl <<endl <<chance <<"chance left" <<endl;
cin>>letter;
chance--;
i=-1;
}
}
}
for(i=0;i <word.length();i++)
{
if(letter==word.at(i)&&chance>0)
{temp.replace(i,1,1,letter);
rigth++;
if(rigth==word.length())
{cout <<"You get it!" <<"[" <<word <<"]" <<endl;
break;
}
}
else{
if(chance>0)
cout <<"Wrong letter!" <<endl;
}
}
}while(rigth < word.length()&&chance > 0);

cout <<"You lose it!" << "[" <<word << "]" << endl;
}
ChargeForward 2008-04-17
  • 打赏
  • 举报
回复
没人理,555~~~
你想当“李逍遥”式的“大侠”吗? 这里无需计算机基础,无需编程经验,你也不必是计算机专业的在校大学生....只要爱好游戏,怀揣梦想! 有一定自主学习能力,跟着刘老师从“编程小白”修炼为游戏研发“大虾”吧!!!学习好Unity,其先决条件是一定要有稳固、扎实的编程基础!课程 《C# For Unity系列之入门篇》配套学习资料链接:http://pan.baidu.com/s/1gflxreN 密码:sou5;刘老师讲Unity学员群(2) 497429806一、热更新系列(技术含量:中高级):A:《lua热更新技术中级篇》https://edu.csdn.net/course/detail/27087B:《热更新框架设计之Xlua基础视频课程》https://edu.csdn.net/course/detail/27110C:《热更新框架设计之热更流程与热补丁技术》https://edu.csdn.net/course/detail/27118D:《热更新框架设计之客户端热更框架(上)》https://edu.csdn.net/course/detail/27132E:《热更新框架设计之客户端热更框架(中)》https://edu.csdn.net/course/detail/27135F:《热更新框架设计之客户端热更框架(下)》https://edu.csdn.net/course/detail/27136二:框架设计系列(技术含量:中级): A:《游戏UI界面框架设计系列视频课程》https://edu.csdn.net/course/detail/27142B:《Unity客户端框架设计PureMVC篇视频课程(上)》https://edu.csdn.net/course/detail/27172C:《Unity客户端框架设计PureMVC篇视频课程(下)》https://edu.csdn.net/course/detail/27173D:《AssetBundle框架设计_框架篇视频课程》https://edu.csdn.net/course/detail/27169三、Unity脚本从入门到精通(技术含量:初级)A:《C# For Unity系列之入门篇》https://edu.csdn.net/course/detail/4560B:《C# For Unity系列之基础篇》https://edu.csdn.net/course/detail/4595C: 《C# For Unity系列之中级篇》https://edu.csdn.net/course/detail/24422D:《C# For Unity系列之进阶篇》https://edu.csdn.net/course/detail/24465四、虚拟现实(VR)与增强现实(AR):(技术含量:初级)A:《虚拟现实之汽车仿真模拟系统 》https://edu.csdn.net/course/detail/26618五、Unity基础课程系列(技术含量:初级) A:《台球游戏与FlappyBirds—Unity快速入门系列视频课程(第1部)》 https://edu.csdn.net/course/detail/24643B:《太空射击与移动端发布技术-Unity快速入门系列视频课程(第2部)》https://edu.csdn.net/course/detail/24645 C:《Unity ECS(二) 小试牛刀》https://edu.csdn.net/course/detail/27096六、Unity ARPG课程(技术含量:初中级):A:《MMOARPG地下守护神_单机版实战视频课程(上部)》https://edu.csdn.net/course/detail/24965B:《MMOARPG地下守护神_单机版实战视频课程(中部)》https://edu.csdn.net/course/detail/24968C:《MMOARPG地下守护神_单机版实战视频课程(下部)》https://edu.csdn.net/course/detail/24979

64,282

社区成员

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

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