Hello community
I'm trying to educate myself with C++. I have used Bjarne Stroustrup's book:
"Programming. Principles and Practice Using C++".
I reached Ch3 and get some trouble with the task p.: 116, #4
I haven't english version of a book, so I'll try to explaine task.
- Declare variable of char type with name friend_sex and initialized it with 0. Offer user input value "m" - if friend is male, and "f" if female. With two "if" statement cout:
If friend male - "If you'll se friend_name, ask him to call me."
If friend female - "If you'll se friend_name, ask her to call me."
So I get something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
#include "std_lib_facilities.h"
#include <iostream>
#include <string>
#include "Test.h"
using namespace std;
int main()
{
string first_name;
string friend_name;
string mail_1;
string mail_2;
string mail_3;
char friend_sex = 0;
char f = 0;
char m = 0;
cout << "Please inpute name of receiver: " << endl;
getline (cin, first_name);
cout << "Please inpute mail: " << endl;
getline (cin, mail_1);
getline (cin, mail_2);
getline (cin, mail_3);
cout << "Please input friend name: " << endl;
getline (cin, friend_name);
cout << "What gender your friend is? Input f or m." << endl;
cin >> friend_sex;
cout << "Dear " << first_name << "," << endl
<< mail_1 << endl
<< mail_2 << endl
<< mail_3 << endl
<< "Did you see " << friend_name << " recently?" << endl;
if (friend_sex == f) cout << "If you will see " << friend_name << " please tell him to call me.";
if (friend_sex == m) cout << "If you will see " << friend_name << " please tell her to call me.";
}
|
And I get some like this:
http://radikal.ru/fp/94a8a98c616149bebca932f7365a1533
http://radikal.ru/fp/dc7bad3de5d44c11adb3974b31cb6457
And 1 more question. What I should use if I need inpute some area with text? Not the simple string?