20: Ask user to enter age, sex ( M or F ), marital status ( Y or N ) and then using following rules print their place of service. If employee is female, then she will work only in urban areas. If employee is a male and age is in between 20 to 40 then he may work in anywhere. If employee is male and age is in between 40 to 60 then he will work in urban areas only. And any other input of age should print "ERROR".

 

// Ask user to enter age, sex ( M or F ), marital status ( Y or N ) and then using following rules print their place of service.
// if employee is female, then she will work only in urban areas.
// if employee is a male and age is in between 20 to 40 then he may work in anywhere
// if employee is male and age is in between 40 t0 60 then he will work in urban areas only.
// And any other input of age should print "ERROR".


#include <iostream>
using namespace std;
int main(){

        int age;
        char sex, marriage;

        cout << "Enter your age: ";
        cin >> age;

            if(age >= 20 && age <=60){
                cout << "Enter your sex 'm' or 'f': ";
                cin >> sex;
                    if(sex == 'm' || sex == 'f'){
                        cout << "Enter your martial status 'y' or 'n': ";
                        cin >> marriage;
                            if(marriage == 'y'|| marriage == 'n'){}
                            else {cout << "Error, invalid choice";
                                return 0;}
                    }

                    else {cout << "Error, 'm' or 'f'";
                            return 0;}
            }

            else {cout << "Error, age limit 20-60\n";
                    return 0;}

                if(sex == 'f'){
                    cout << "You can work only in urban areas \n";
                }
                else if(sex=='m' && age>=20 && age<=40){
                    cout << "You can work anywhere \n";
                }
                else if(sex=='m' && age>40 && age<=60){
                    cout << "You can work only in urban areas \n";
                }

    return 0;
}



Comments

Popular posts from this blog

88: Using switch statement Write a C program to input marks of five subjects Physics, Chemistry, Biology, Mathematics and Computer. Calculate percentage and grade according to following: // Percentage >= 90% : Grade A Percentage >= 80% : Grade B Percentage >= 70% : Grade C Percentage >= 60% : Grade D Percentage >= 40% : Grade E Percentage < 40% : Grade F

205: Book Catalog: Define a struct to represent a book with attributes like title, author, and publication year. Write a program to create a catalog of books by taking user input and display books published after a certain year.

15: Take input of age and name of 3 people by user and determine oldest and youngest among them with his age. -_-_-_-_-_-_-_-_-(line with spaces input concept)-_-_-_-_-_-_-_-_