Modify this code to accept M for male and F for female in addition to m and f cu
ID: 3623125 • Letter: M
Question
Modify this code to accept M for male and F for female in addition to m and f currently in the code, and display an error message for input different from m, M, f, or F.#include "std_lib_facilities.h"
int main()
{
cout << "What is your friend’s name?" << endl;
string friend_name;
cin >> friend_name;
cout << "What is the gender of your friend (m/f)? " << endl;
char friend_sex = 0;
cin >> friend_sex;
if (friend_sex == ’m’)
cout << "If you see " << friend_name <<
" please ask him to call me." << endl;
else
cout << "If you see " << friend_name <<
" please ask her to call me." << endl;
}
Explanation / Answer
please rate - thanks
#include "std_lib_facilities.h"
int main()
{
cout << "What is your friend's name?" << endl;
string friend_name;
cin >> friend_name;
cout << "What is the gender of your friend (m/f)? " << endl;
char friend_sex = 0;
cin >> friend_sex;
if (friend_sex == 'm'||friend_sex == 'M')
cout << "If you see " << friend_name <<
" please ask him to call me." << endl;
else if(friend_sex == 'f'||friend_sex == 'F')
cout << "If you see " << friend_name <<
" please ask her to call me." << endl;
else
cout<<"Invalid input"<<endl;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.