Activity 8 - Hand-coding challenge

In this activity, you will write a short program that computes the price of an item at a check-out counter depending on sales tax and whether the customer has a membership card (that would earn them 10% off) and computes the final price.

Part 1 - Hand-coding in groups

Requirements for calculate_final_price:

  • calculate_final_price should increase the price by the tax rate and reduce the price by 10% if there is a membership card
  • calculate_final_price should print the final price like the example below as well as returning the final numerical value value

Example:

> calculate_final_price(100.00, 0.08, true)
Final Price is $82.80
#![allow(unused)]
fn main() {
fn calculate_final_price(/* fill in parameters */) -> /* fill in return type */ {
    // Your implementation here




















    
}
}

Requirements for main:

  • Include a few test cases in main.rs() following the example, passing in the sticker price, tax rate, and boolean for whether they have a membership flag
  • Your test cases should explore a range of inputs and "edge cases" that could conceivably break your code so can demonstrate error handling
fn main() {
    // Example: let total = calculate_final_price(100.00, 0.08, true);














}

Things to think about:

  • What if your final price has more or less than two decimal places? (hint: println!("{:.3}", 0.1); prints 0.100)
  • Does it matter in what order the tax and discount are applied?
  • What would happen if the sticker price were very low (like 2 cents), or negative?

Part 2 - Swap for feedback

When I announce, you'll swap papers with another group and look at their solution. Take a minute to give them feedback including:

  • Any highlights of what they did well
  • Any bugs you notice
  • Any style feedback

At the end, I will collect papers and pick a couple (anonymized) to display on the screen for discussion.