Calculated member fees
If you run your CiviCRM on a Drupal instance you can use Webform CiviCRM module in combination with Webform Calculator module that you can use for that exact scenario.

Alternatively - see here for an example of how you can use conditionals to build your own fees: How can I create early bird fees with Webform CiviCRM? - the example is for a participant (event) fee, but a membership fee can be built similar to this.