Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C PROGRAM Panic buying is the act of buying large amounts of a product in anticipation of an emergency. The most recent example is the

C PROGRAM

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands-On Database

Authors: Steve Conger

2nd Edition

0133024415, 978-0133024418

More Books

Students also viewed these Databases questions