2017-11-30 7 views
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; 
} 
+0

、それはあなたの絞首刑執行人の表示コードを簡素化するために些細です:https://ideone.com/Xn9GSC – paddy

答えて

2

char new[5]={0};に見えるなら、私を許して。ただし、newはC++でkeywordであり、予約されている目的にのみ使用できます。あなたの配列の名前を変更してください。 http://en.cppreference.com/w/cpp/language/identifiersから

識別子は、名前のオブジェクト、参照、関数、列挙子、種類、クラスメンバー、名前空間、テンプレート、テンプレート特殊、パラメータパック、後藤ラベル、および他のエンティティに使用することができ、次の例外を除いて:

  • キーワードである識別子は、他の目的では使用できません。
  • 二重アンダースコアの識別子は予約されています。
  • アンダースコアで始まり、大文字で始まる識別子は予約されています。
  • アンダースコアで始まる識別子は、グローバル名前空間に予約されています。
  • あなたが胸の前に左の腕を描画しているので
関連する問題