各位大侠 救救我啊!!! 编译出来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;
}
...全文
121 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~~~

64,849

社区成员

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

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