0
私がやっている小さなプロジェクトのハングマンゲームをまとめようとしていますが、これらのエラーが発生しています。私は誰かがこれらのエラーを参照するための正しい方向で私を指すことができるかどうか疑問に思っていた。私はコードの中で受け取っているエラーを指摘しました。私はnew
という名前の配列を作成しようとしているコーディングに比較的新しいですので、これは些細なC++を使ってハングマンゲームでエラーが発生しました
#include<iostream>
#include<string>
int main()
{
int t=1;
while(t>0)
{
char c;
char a[]="hello";
int wrong=0;
std::cout<<"guess the word";
char new[5]={0};<----------------error: Expected unqualified-id
int no;
char letter;
for(int i=0;i<a.length;i++)<---------error: Member reference base type 'char [6]' is not a structure or union
{
std::cout<<"x";
}
while(wrong<7 && strcmp(new,a)!=0)<---------error: Expected a type
{
no=0;
std::cin>>letter;
for(int i=0;i<5;i++)
{
if(new[i]==letter)<----------------error: Expected a type
{
no=1;
std::cout<<"yes"<<std::endl;
}
}
if(no<1)
{
std::cout<<"no"<<std::endl;
wrong++;
if(wrong==1)
{
std::cout<<" O"<<std::endl;
}
if(wrong==2)
{
std::cout<<" O"<<std::endl;
std::cout<<"/"<<std::endl;
}
if(wrong==3)
{
std::cout<<" O"<<std::endl;
std::cout<<"/|"<<std::endl;
}
if(wrong==4)
{
std::cout<<" O"<<std::endl;
std::cout<<"/|\\"<<std::endl;
}
if(wrong==5)
{
std::cout<<" O"<<std::endl;
std::cout<<"/|\\"<<std::endl;
std::cout<<" |"<<std::endl;
}
if(wrong==6)
{
std::cout<<" O"<<std::endl;
std::cout<<"/|\\"<<std::endl;
std::cout<<" |"<<std::endl;
std::cout<<"/"<<std::endl;
}
if(wrong==7)
{
std::cout<<" O"<<std::endl;
std::cout<<"/|\\"<<std::endl;
std::cout<<" |"<<std::endl;
std::cout<<"/ \\"<<std::endl;
}
}
}
if(wrong==7)
{
std::cout<<"play again"<<std::endl;
std::cin>>c;
}
else
{
std::cout<<"Congratulations!!!"<<std::endl;
std::cout<<"play again"<<std::endl;
std::cin>>c;
}
if(c=='y')
{
t=1;
}
else
{
t=0;
}
}
return 0;
}
、それはあなたの絞首刑執行人の表示コードを簡素化するために些細です:https://ideone.com/Xn9GSC – paddy