2016-11-07 30 views
-1

こんにちは私はCで+ +のifステートメントに問題があります。私のコードをコンパイルすると、 "no operator" || "これらのオペランドにマッチする"というエラーが出ます。どんな推測?このプロジェクトは、私がビジュアルスタジオで作成している小さなテキストベースのゲームです。オペレータは一致しません||これらのオペランド

#include "stdafx.h" 
#include <iostream> 
#include <iomanip> 
#include <string> 
#include <cmath> 
#include <fstream> 

using namespace std; 

//Prototypes 
void introScreen(int); 
string characterCreation(string); 



int choice; 
string characterName, wepon1, wepon2, bow, sword, mace; 

const string sword = sword; 
const string bow = bow; 
const string mace = mace; 

// Functions 

int main() 
{ 
    introScreen(choice); 

    return 0; 
} 


void introScreen(int choice) 
{ 

    cout << "----------------------------------------\n" 
     << "Welcome to the arena!\n" 
     << "Select a menu option\n" 
     << "-----------------------------------------\n" 
     << "1. New Game\n" 
     << "2. Load\n" 
     << "3. Exit\n\n" 
     << "Enter your desired number "; 
    cin >> choice; 

    if (choice == 1) 
     characterCreation(characterName); 
    else 
     if (choice == 2) 
      exit(0); 
     else 
      if (choice == 3) 
       exit(1); 

} 


string characterCreation(string characterName,string wepon1,string wepon2, const string bow, const string sword, const string mace) 
{ 

    cout << "Welcome to the character creation menu!\n" 
     << "Enter your name\n" 
     << "Name: "; 
    cin.ignore(); 
    getline(cin, characterName); 

    ofstream loadFile("Save.txt"); 
    loadFile << characterName << endl; 

    cout << "\nEnter 2 wepons\n" 
     << "Wepon list\n\n" 
     << "Sword\n" 
     << "Mace\n" 
     << "Bow\n"; 
    cin >> wepon1, wepon2; 

    if (wepon1 || wepon2 != bow || sword || mace) 
    { 
     cout << "\n\nThose wepons are invalid! Enter new ones\n"; 
     cout << "\nEnter 2 wepons\n" 
      << "Wepon list\n\n" 
      << "sword\n" 
      << "mace\n" 
      << "bow\n"; 
     cin >> wepon1, wepon2; 
    } 

    loadFile << wepon1 << endl 
     << wepon2 << endl; 


    return characerName; 
} 
+5

論理 "または"はこのようには機能しません。 *各*武器と*各*タイプを比較する必要があります。 –

+0

@FredLarson私は、人々がPythonで間違いを犯したと思っていました。論理的な 'と'と 'または'が単語として綴られています。私は間違っていたと思います。 –

+2

ああ、これはうまくいきません: 'cin >> wepon1、wepon2;'。 –

答えて

0

'||'演算子は論理条件の評価であり、文字列型の評価を依頼しています。一般に、文字列の値が評価されると、(weapon1!= "")then ...

また、値の設定方法に注意してください。文字列値は二重引用符で渡されます。

+0

ありがとうございました!私はそれを認識しませんでした。助けてくれてありがとう – Loganastan

関連する問題