Question: I have a potential maths / formula / algorithm question which I would like help on.

I've written a questionnaire application in ASP.Net that takes people through a series of pages. I've introduced conditional processing, or branching, so that some pages can be skipped dependent on an answer, e.g. if you're over a certain age, you will skip the page that has Teen Music Choice and go straight to the Golden Oldies page.

I wish to display how far along the questionnaire someone is (as a percentage). Let's say I have 10 pages to go through and my first answer takes me straight to page 9. Technically, I'm now 90% of the way through the questionnaire, but the user can think of themselves as being on page 2 of 3: the start page (with the branching question), page 9, then the end page (page 10).

How can I show that I'm on 66% and not 90% when I'm on page 9 of 10?

For further information, each Page can have a number of questions on that can have one or more conditions on them that will send the user to another page. By default, the next page will be the next one in the collection, but that can be over-ridden (e.g. entire sets of pages can be skipped).

Any thoughts? :-s

Answer: 
Simple answer is you can't. From what you have said you won't know until you have reached the end how many pages the user is going to see so you can't actually display an accurate result.

What you could do to get a better result as in your example is to assume they are going through all the remaining pages. In this case you would on any page have:

1. Number of pages gone through so far including current (visited\_pages)
2. Number of the current page (page\_position)
3. Total number of pages (total\_pages)

The maximum number of pages is now:

```
max_pages = total_pages - page_position + visited_pages

```

You can think of total\_pages-page\_position as being the number of pages left to visit which makes the max\_pages quite intuitive.

So in the 10 page example you gave visited\_pages = 2 (page 1 and page 9), page\_position = 9 and total\_pages = 10. 

so max\_pages = 10-9+2 = 3.

then to work out the distance through you just do 

```
progress = visited_pages/max_pages*100

```

One thing to note is that if you were to go to pages 1,2,3,4,9,10 then your progress would be 10%,20%,30%,40%,83%,100% so you would still get a strange jump that may confuse people. This is pretty much inevitable though.
Logically unless the user's question graph is predetermined, you can not predetermine their percentage complete. 

That being said.

What you can do is build a full graph of the users expected path based on what information you know: what questions they have completed, and what questions they have to take, and simply calculate a percentage. 

This will probably involve a data structure such as a linked list to calculate where they have been, and what the user has left to complete, this implementation is up to you.

The major caveat here is you have to accept that if the users question graph changes, so will their percent completed. Theoretically they could display 90% and then it changes and they will display 50%.