我正在根据我的教科书进行练习,并且一直遇到问题。这是代码。
#include <iostream>
using namespace std;
int main(){
string name;
string friend_name;
char friendsex;
char m = 'm';
char f = 'f';
cout << "Enter the name of the person you would like to write to" << endl;
cin >> name;
cout << endl << "Dear " << name <<", "
<< endl
<< endl
<< "Hey how are you? I myself have been fine recently. I've been wanting to do some catching up with you"
<< endl
<< endl
<< "Please enter the name of a friend now"
<< endl;
cin >> friend_name;
cout << endl << "Hey how are you? I myself have been fine recently. I've been wanting to do some catching up with you. Have you seen " << friend_name << " recently?" << endl << endl;
cout << "Please enter the sex of your friend (m/f)"
<<endl;
cin >> friendsex;
if(friendsex = 'm'){
cout << "If you have, could you please tell him to call me?";
}
else if(friendsex = 'f'){
cout << "If you have, could you please tell her to call me?";
}
return 0;
}
我不知道如何使 if 语句与用户输入的字符一起工作。即使我输入 f,它也总是运行男性语句。