Why is my compiler saying that 'm' and 'f' are not declared in the scope, and how would I fix this?
I am novice, thanks for your patience.
1 2 3 4 5 6 7 8 9
char friend_sex = 0;
cout<<"Please enter 'm' for male friend or 'f' for female friend.\n";
cin>>friend_sex;
if (friend_sex = m){
cout<<"If you see "<<friend_name<<" please ask him to call me.\n";
}
if (friend_sex = f){
cout<<"If you see "<<friend_name<<" please ask her to call me.\n";
}
#include "std_lib_facilities.h"
int main()
{
cout<<"Please enter the name of the person you wish to write to.\n\n\n";
string first_name; // variable of type string
cin>>first_name; // read first_name
cout<<"\n\n\nDear "<<first_name<<",\n";
cout<<" Hi, how are you? I miss you dearly. I am doing fine.\n\n\n";
cout<<"Please provide the name of another friend.\n";
string friend_name;
cin>>friend_name; // read friend_name
cout<<"\n\n\nDear "<<first_name<<",\n";
cout<<" Hi, how are you? I miss you dearly. I am doing fine. ";
cout<<"Have you seen "<<friend_name<<" lately?\n\n\n";
char friend_sex = 0;
cout<<"Please enter 'm' for male friend or 'f' for female friend.\n";
cin>>friend_sex;
if (friend_sex = 'm'){
cout<<"If you see "<<friend_name<<" please ask him to call me.\n";
}
if (friend_sex = 'f'){
cout<<"If you see "<<friend_name<<" please ask her to call me.\n";
}
}
You had time to make one more error. Instead of the assignment operator (=) you must use the comparision operator (==)
1 2 3 4 5 6
if (friend_sex =='m'){
cout<<"If you see "<<friend_name<<" please ask him to call me.\n";
}
if (friend_sex =='f'){
cout<<"If you see "<<friend_name<<" please ask her to call me.\n";
}