LESSON+5

//**Selective structures: If... then... end if**//
 Selective structures are the means by which a program chooses between tow or more conditions. For example, let's say you have a class list and want to output only those students whose last name begins with "T". You would use a selective structure (sometimes called a decision structure) in order to do so. The syntax for such a structure is:  //** if... **// **//elsif...// ** **//else...// ** **//end if.// ** Try this:

%Choosing between two alternatives  **var mark: int**  **put "Enter mark:"..**  **get mark**  **if mark >= 50 then**  **put "you pass"**  **else**  **put "time to enroll in summer school "**  **end if**

<span style="font-family: Arial,Helvetica,sans-serif;">Notice that as with repetitive structures, selective structures must be "ended": each if statement must be accompanied by an end if. Try this:

<span style="font-family: 'Courier New',Courier,monospace; font-size: 120%;">%Choosing between many alternatives <span style="font-family: 'Courier New',Courier,monospace; font-size: 120%;"> **var mark:int** <span style="font-family: 'Courier New',Courier,monospace; font-size: 120%;"> **<span style="font-family: Arial,Helvetica,sans-serif;">put "Enter mark:".. ** <span style="font-family: 'Courier New',Courier,monospace; font-size: 120%;"> **<span style="font-family: Arial,Helvetica,sans-serif;">get mark ** <span style="font-family: 'Courier New',Courier,monospace; font-size: 120%;"> **<span style="color: #000080; font-family: Arial,Helvetica,sans-serif;">if <span style="font-family: Arial,Helvetica,sans-serif;">mark >= 80 then ** <span style="font-family: 'Courier New',Courier,monospace; font-size: 120%;"> **<span style="font-family: Arial,Helvetica,sans-serif;">put "You got and A " ** <span style="font-family: 'Courier New',Courier,monospace; font-size: 120%;"> **<span style="color: #000080; font-family: Arial,Helvetica,sans-serif;">elsif <span style="font-family: Arial,Helvetica,sans-serif;"> mark >= 70 then ** <span style="font-family: 'Courier New',Courier,monospace; font-size: 120%;"> **<span style="font-family: Arial,Helvetica,sans-serif;">put "You got a B " ** <span style="font-family: 'Courier New',Courier,monospace; font-size: 120%;"> **<span style="color: #000080; font-family: Arial,Helvetica,sans-serif;">elsif <span style="font-family: Arial,Helvetica,sans-serif;"> mark >= 50 then ** <span style="font-family: 'Courier New',Courier,monospace; font-size: 120%;"> **<span style="font-family: Arial,Helvetica,sans-serif;">put "You got a C " ** <span style="font-family: 'Courier New',Courier,monospace; font-size: 120%;"> **<span style="color: #000080; font-family: Arial,Helvetica,sans-serif;">else ** <span style="font-family: 'Courier New',Courier,monospace; font-size: 120%;"> **<span style="font-family: Arial,Helvetica,sans-serif;">put "Receiving an F could jeopardise your summer " ** <span style="font-family: 'Courier New',Courier,monospace; font-size: 120%;"> **<span style="color: #000080; font-family: Arial,Helvetica,sans-serif;">end if **

<span style="font-family: Arial,Helvetica,sans-serif; font-size: 120%;">Notice that the else condition takes care of any possibility not otherwise accounted for by the series of if's & elsif's. <span style="font-family: Arial,Helvetica,sans-serif; font-size: 120%;"> //** Task: **//
 * 1) Modify any program you have written such that it is menu driven.
 * 2) Write a program which quizzes the user on some academic subject other than computer science (for example geography or history). Give the user three chances at each of the ten questions. Inform the user if they guessed correctly or incorrectly.
 * 3) Modify 2 such that it calculates a percentage correct and creates a graph displaying the percentage results
 * Remember to make your programs as user-friendly as possible, never insult the intelligence of the user.**