//Writing a letter
#include <iostream>
using namespace std;
int main() {
string first_name; //Name of addressee
string friend_name; //Name of a friend top be mentioned in the letter
char friend_sex, m, f; //variable for gender of friend
friend_sex = 0;
cout << "\nEnter the name of the person you want to write to: ";
cin >> first_name;
cout << "Enter the name of a friend: ";
cin >> friend_name;
cout << "Enter friend's sex(m/f): "; //Enter m or f for friend
cin >> friend_sex; //Place m or f into friend_sex
cout << "\nDear " << first_name << ",\n\n"
<< " How are you? I am fine. I miss you!blahhhhhhhhhhhhhhhh.\n"
<< "blahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.\n"
<< "Have you seen " << friend_name << " lately? ";
//braces only necessary if there are more than one statement in the if function
if(friend_sex == m) {
cout << "If you see " << friend_name << ", please ask him to call me.";
} //If friend is male, output this
if(friend_sex == f) {
cout << "If you see " << friend_name << ", please ask her to call me.";
} //If friend is female, output this
return(0);
}
Вот что на самом деле выходит:
Enter the name of the person you want to write to: MOM
Enter the name of a friend: DAD
Enter friend's sex(m/f): m
Dear MOM,
How are you? I am fine. I miss you! blahhhhhhhhhhhhhhhhh.
blahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.
Have you seen DAD lately?
Эта программа имитирует короткое письмо. Вывести блок слов достаточно просто, но когда я хочу, чтобы в письме были помещены некоторые условные выражения, у меня проблемы. Несмотря на то, что я ввел friend_sex (m / f), когда программа спрашивает меня, вывод из оператора if не материализуется. Почему?