Linear+Search+(programming)

Introduction
The principle of a linear search is to loop through a list of numbers searching for a specific number. If the number is found the loop should exited and the number displayed.

A list of numbers is as follows: 7 1 2 9 4 8 5
 * Example**

Carry out a linear search for the number 2.

The program should repeat through the list, comparing each number with the number being searched for. The first number in the list is 7. Is this the number being searched for? No. The next number in the list is 1. Is this the number being searched for? No. The next number in the list is 2. Is this the number being searched for? Yes. What position is this number in the list? Position 3. Exit the loop and output that the number was found in position 3.

Specification
Write a program which carries out a linear search

Input Process Output
Inputs: Number to be searched for Process: Perform a linear search Output: Position in list of number

Algorithm
1. get search_number 2. repeat for all numbers in list

2.1 if current_number = search_number then 2.1.1 position = current_item position 2.1.2 exit loop 2.2 end if

3. end repeat 4. display position

The Task
1. Draw a screen design, with labelled fields and buttons 2. Copy the algorithm 3. Write the program

Extension
Adapt your program so that it displays an appropriate message if the number is not found in the list.