http://autoinsurance-list.blogspot.com/ .

Sunday, October 21, 2012

Is my pseudocode correct?

Is my pseudocode correct?

Question by flarithkiroken: Is my pseudocode correct? Here is the prompt: "Plan the logic for an insurance company's premium-determining program. The program calls a method that prompts the user for the type of policy needed--health or auto. Pass the user's response to a second method, where the premium is set--$ 250 for a health policy or $ 175 for an auto policy. Pass the premium amount to a third module for printing." And here is my pseudocode: start num premium num policyNum num premiumVal policyNum = policyNeeded() premium = premiumVal(policyNum) premiumMessage(premiumVal) stop policyNeeded() num policyCode print "Type of policy needed? (1 for health, 2 for auto)" get policyCode if policyCode > 2 OR policyCode < 1 print "Please re-enter a valid policy number" get policyCode endif return policyCode premiumVal(policyNum) num premium if 1 premium = 250 else premium = 175 endif return premium premiumMessage(premium) string TWO_FIDDY = "Your health premium will be $ 250.00." string ONE_SETTY = "Your auto premium will be $ 175.00." if premium = 250 print TWO_FIDDY else print ONE_SETTY endif Please let me know if it's logically functional, and if not, what corrections I need to make! Thanks! Best answer:

Answer by Mark W
it kind of works, not sure about your validation of the input of policy type I would have used something more like policyNeeded() num policyCode string errortext = "" boolean policycodeOK = false while policycodeOK = false print errorText & "Type of policy needed? (1 for health, 2 for auto)" get policyCode if policyCode = 2 OR policyCode = 1 policycodeOK = true else errorText "Please re-enter a valid policy number" endif while end return policyCode I also would have used the variable passed to the printing in the final print out, this could be done by changing the premium variable to a string then using ... premiumMessage(premium) string printout = "Your premium will be $ " & premium print printout

Add your own answer in the comments!

0 comments:

Post a Comment

 
Related Posts with Thumbnails