calculate_amount code