oops, typo in the round() function... it should be: #round( (correctanswers/ttlquestions)*100 )
[i had a comma in there which should not be there...] On 04/03/2011 12:11 , Azadi Saryev wrote: > Something like this: > > a) at the top of your action page add: > <cfset ttlquestions = 5><!--- total number of q's in the test ---> > <cfset correctanswers = 0> > > b) in the table showing answers in your action page add <cfset > correctanswers = correctanswers+1> to all your <cfif> blocks like so: > <cfif Form.Q1 EQ Ans1> > <img src="Images/Good.gif" alt="Correct" width="16" height="16"> > <cfset correctanswers = correctanswers+1> > <cfelse> > ...[your current code as is here]... > </cfif> > > c) at the bottom of your action page show the score: > <cfoutput>Your Score: #round( (correctanswers/ttlquestions)*100, > )#%</cfoutput> > > Azadi > > On 04/03/2011 11:48 , John Eubanks wrote: >> Anyone know how to calculate a percentage from form variables. I >> have a simple quiz (five questions) with multiple choice answers. I >> have the correct answers set using cfset on the processing page. >> However, I need to run a percentage so the display shows something >> like: Score: 80%. >> >> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:342743 Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm