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;
}
if (direction == 'o' || 'O')
should be
if (direction == 'o' || direction == 'O')
and the same thing in the other if
statement.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.