Online Book Merchants offers premium customers 1 free book with every purchase of 5 or more books and offers 2 free books with every purchase of 8 or more books. It offers regular customers 1 free book with every purchase of 7 or more books, and offers 2 free books with every purchase of 12 or more books. Write a statement that assigns free Books the appropriate value based on the values of the bool variable is Premium Customer and the int variable n books Purchased
LANGUAGE: Visual Basic
CHALLENGE: Online Book Merchants offers premium customers 1 free book with every purchase of 5 or more books and offers 2 free books with every purchase of 8 or more books. It offers regular customers 1 free book with every purchase of 7 or more books, and offers 2 free books with every purchase of 12 or more books. Write a statement that assigns free Books the appropriate value based on the values of the bool variable is Premium Customer and the int variable n books Purchased.
SOLUTION:
If isPremiumCustomer Then If (nbooksPurchased > 4) And (nbooksPurchased < 8) freebooks = 1 ElseIf (nbooksPurchased >= 8) freebooks = 2 ElseIf (nbooksPurchased < 5) freebooks = 0 End If Else If (nbooksPurchased > 6) And (nbooksPurchased < 12) freebooks = 1 ElseIf (nbooksPurchased >= 12) freebooks = 2 ElseIf (nbooksPurchased < 7) freebooks = 0 End If End If