Skip to content

2016-10: Order Total

Suppose you have a numeric vector that is the list of prices for a set of retail products. You also have a numeric vector that is the number ordered of each product. Write a function that takes as its right argument a vector of prices and as its left argument a numeric vector that indicates the number ordered and returns the total cost for the order. In case you hadn't realized it, this is an application the dot product. The dot product of two vectors A = [A1, A2, …,An] and B = [B1, B2, …,Bn] is defined as

Examples:

      5 0 2 (your_function) 2.99 4.99 1.99
18.93
      0 0 0 (your_function) 2.99 4.99 1.99
0 
your_function ←

Solutions

Video Thumbnail YouTube

Chat transcript Code on GitHub