• 0

Modules (Pseudocode) So confused


Question

I am so confused about this exercise in my textbook. This chapter is about modules. I need to get input from the user, calculate the assessment value, and calculate the property tax. Here's what I have so far:

 

 

Module main ( )

     Declare Real actualValue

     Display "Enter value of land:"

     Input actualValue

     Call getAssessmentValue (actualValue)

     Call getPropertyTax 

End Module

 

Module assessmentValue (Real value)

     Declare Real assessmentValue

     Set assessmentValue = value * 0.60

     Display "Assessment value is:", assessmentValue

End Module

 

Module getPropertyTax 

     Declare Real propertyTax

     Set propertyTax = (assessmentValue / 100) * 0.64

     Display "Property tax is:", propertyTax

End Module

 

I don't think this is going to work because I'm accessing the local variable assessmentValue in a module it wasn't declared in. Does it need to be made a global variable before the main module? I'm confused about how it would be a global variable since I have a formula attached to it that involves the actualValue variable. 

 

I would be grateful for any advice I could get! 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

Your pseudocode doesn't look right to me. It looks like you're using "Modules" like functions. My interpretation of a module is "a code structure containing one or more functions". So you'd only have one module, but many functions, like this:

Function main () # Doesn't belong to a module.
  Declare Real actualValue
  Display "Enter value of land:"
  Input actualValue
  Call TaxCalculator.getAssessmentValue (actualValue)
  Call TaxCalculator.getPropertyTax
End Function

Module TaxCalculator

  Variable Real assessmentValue = 0

  Function getAssessmentValue(Real value)
    Set assessmentValue = value * 0.60
    Display "Assessment value is:", assessmentValue
  End Function

  Function getPropertyTax 
    Declare Real propertyTax
    Set propertyTax = (assessmentValue / 100) * 0.64
    Display "Property tax is:", propertyTax
  End Function

End Module
That said, global (or module-wide) variables are bad (M'kay), so you're better off returning your results. Like this:

Function main () # Doesn't belong to a module.
  Declare Real actualValue
  Display "Enter value of land:"
  Input actualValue

  Declare Real assessmentValue
  Call TaxCalculator.getAssessmentValue (actualValue) -> assessmentValue

  Declare Real propertyTax
  Call TaxCalculator.getPropertyTax (assessmentValue) -> propertyTax
End Function

Module TaxCalculator

  Function calculateAssessmentValue(Real value)
    Set assessmentValue = value * 0.60
    Display "Assessment value is:", assessmentValue
    return assessmentValue
  End Function

  Function getPropertyTax(Real assessmentValue)
    Declare Real propertyTax
    Set propertyTax = (assessmentValue / 100) * 0.64
    Display "Property tax is:", propertyTax
    return propertyTax
  End Module

End Module
That all being said, remember that pseudocode is very subjective, so I could be way off base with what you want (or need), so take the time to draw your own conclusions :)
Link to comment
Share on other sites

This topic is now closed to further replies.