Loganastan
Loganastan

Reputation: 17

no operator matches || these operands

Hi im having trouble with an if statement in C++. When I compile my code I get an error stating " no operator "||" matches these operands". Any guesses? The project is a small text based game I'm creating in visual studio.

#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;
}

Upvotes: 0

Views: 2006

Answers (1)

Myca A.
Myca A.

Reputation: 81

The '||' operator is an evaluation of a logical condition and you are asking it to evaluate a string type. Generally, when strings values are evaluated, they are evaluated as if (weapon1 != "") then...

Also, be careful about how you set the value. String values are passed inside double quotation marks.

Upvotes: 1

Related Questions