Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- double age;
- cin >> age;
- string gender;
- cin >> gender;
- if (age < 16) {
- if (gender == "m") {
- cout << "Master" << endl;
- }
- else if (gender == "f") {
- cout << "Miss" << endl;
- }
- }
- else {
- if (gender == "m") {
- cout << "Mr." << endl;
- }
- else if (gender == "f") {
- cout << "Ms." << endl;
- }
- }
- return 0;
- }
- Решение с тернарен оператор:
- #include <iostream>
- using namespace std;
- int main() {
- double age;
- cin >> age;
- string gender;
- cin >> gender;
- cout << (age < 16 ? gender == "m" ? "Master" : "Miss" : gender == "m" ? "Mr." : "Ms.") << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement