Question
Panic buying is the act of buying large amounts of a product in anticipation of an emergency. The most recent example is the shortage of
Panic buying is the act of buying large amounts of a product in anticipation of an emergency. The most recent example is the shortage of items such as face masks, food, bottled water, milk, and toilet paper in the beginning of the COVID-19 pandemic. To avoid this problem, a local grocery store has adopted the following policy for certain items. For an item with cost C, the client will pay C dollars for the first unit purchased, 2C dollars for the second unit purchased, 3C dollars for the third unit purchased, and so on. Thus, a client must pay iC dollars for the i-th unit purchased. If a client must buy N units of an item with cost C and has D dollars in his wallet, will the client have enough money? If not, how many extra dollars will the client need to complete this purchase? 1. The program takes the price per unit (C) of a certain item, the desired number of units (N) and an amount of dollars (D) as input. It computes the total cost of N units and checks if D dollars are enough to complete the purchase. If yes, the program prints a message. Otherwise, it prints how many extra dollars are necessary to complete the purchase. 2. Input validation: the program validates the input price (greater than 0), number of units (greater than 0), and amount of dollars (greater than or equal to 0). If any of the three inputs is invalid, the program prints a message and exits. Hint: use the counter of the loop to compute the price of the i-th unit. Example #1: Enter item price: 3 Enter number of units: 4 Enter money amount: 17 Needs 13 dollar(s) to complete the purchase!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started