Site hosted by Angelfire.com: Build your free website today!

Thinking is more interesting than knowing, but less interesting than looking.

     TEILHARD DE CHARDIN

 
Program #11
 

 

 

 

 

 


This program will require the use of many decision-making structures. (See chapter seven.)  You will need some ‘if’ statements and a switch.  The switch is explained on page 131 of our textbook.

 

USING ifs and a SWITCH

As a member of the selection committee for the prestigious Royal Order of the Moose, you need to evaluate applications for membership.

 

Ask each applicant four questions… 1) Name

                                                            2) Age

                                                            3) Sex

                                                            4) Yearly income

 

A switch statement can only consider one item at a time.  You must prepare for it with some ‘if’ statements like this…

                        cin>>age;

            if (age < 13) group=1;

            if (age >= 13 && age <= 20) group=2;

            if (age >21 && age <= 62) group=3;

            if (age < 62) group=4;

                        switch (group)

                                    {

                                        case1: strcpy (status, “reject”);

                                                   if (income > 50000)

                                                            {

                                                            strcpy(status, “accepted”;

                                                            fee=500;

                                                            } break;

                                        case2: fee=150

                                                   if (sex == ‘m’)

{

fee=100;

                                                            strcpy (status, “accepted”);

                                                            } break;

 

and so on. You should also have a default at the end of the cases to “trap” all other situations.

                                                            AGE

           

SEX                 0-12                 13-20               21-62               over 62

I_____________I___________I____________I___________I____________I

            M                     Reject              100                  200                  300

            F                      Reject              150                  200                  250     

There are a few conditions that will adjust the fee from the above chart.

            If the yearly income exceeds $100, 000, increase the fee by 20%.

If they are age 0-12 and the yearly income exceeds $50, 000 they will be accepted with a fee of $500.

 

Print the chart below.

SHELBY ROYAL ORDER OF THE MOOSE

Name: Stanley Tupac

Age: 30           

Sex: M

Yearly income: $86000.00

Status: Accepted                      Fee: $200.00

            We welcome Mr. Stanley Tupac as a Moose.

 

SHELBY ROYAL ORDER OF THE MOOSE

Name: Puffy Chicky

Age: 9

Sex: F

Yearly income: $50.00

Status: Rejected

            Sorry, please apply again in the future.

                                                           

SHELBY ROYAL ORDER OF THE MOOSE

Name: S.D. Dogge

Age: 29

Sex: M

Yearly income: 120000.00

Status: Accepted                      Fee: $240.00

            We welcome Mr. S.D. Dogge as a Moose

                       

Welcome!