thugnasty
thugnasty

Reputation: 5

Trouble with setting string by comparing char

I'm trying to get char input from the user, then set a string based off the char that was typed. What am I doing wrong?

#include <iostream>
#include <string>
using namespace std;

int main()
{
    char direction;
    string printDirection;

    cout << "Inbound or Outbound? (I or O)" << endl;
    cin >> direction;
    if (direction == 'o' || 'O'){
        printDirection = "Outbound";
    }
    else if(direction == 'i' || 'I'){
        printDirection = "Inbound";
    }
    else{
        cout << "Error";
        return 1;
    }
    printDirection;

    return 0;
}

Upvotes: 0

Views: 42

Answers (1)

Silvio Mayolo
Silvio Mayolo

Reputation: 70337

if (direction == 'o' || 'O')

should be

if (direction == 'o' || direction == 'O')

and the same thing in the other if statement.

Upvotes: 1

Related Questions