Question: There is a JAR full of candies for sale at a mall counter. JAR has the capacity N, that is JAR can contain maximum N candies when JAR is full. At any point of time. JAR can have M number of Candies where M<=N. Candies are served to the customers. JAR is never remain empty as when last k candies are left. JAR if efilled with new candies in such a way that JAR get full. Write a code to implement above scenario. Display JAR at counter with available number of candies. Input should be the number of candies one customer can order t point of time. Update the JAR after each purchase and display JAR at Counter. Output should give number of Candies sold and updated number of Candies in JAR Input is more than candies in JAR, return: "INVALID INPUT" iven, 1-10, where N is NUMBER OF CANDIES AVAILABLE =< 5, where k is number of minimum candies that must be inside JAR ever. xample 1:(N = 10, k =< 5) mput Value utput Value UMBER OF CANDIES SOLD:3 UMBER OF CANDIES AVAILABLE : 7 xample: (N=10, k<=5) put Value utput Value VALID INPUT NUMBER OF ANDIES LEFT:10 Code:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
7. Need C, C++, Java, Python, or Perl code for the below question. Important: Do not copy codes from prepinsta.com.
Coding Question /
Question: There is a JAR full of candies for sale at a mall counter. JAR has the
capacity N, that is JAR can contain maximum N candies when JAR is full. At any
point of time. JAR can have M number of Candies where M<=N. Candies are served
to the customers. JAR is never remain empty as when last k candies are left. JAR if
refilled with new candies in such a way that JAR get full.
Write a code to implement above scenario. Display JAR at counter with available
number of candies. Input should be the number of candies one customer can order
at point of time. Update the JAR after each purchase and display JAR at Counter.
Output should give number of Candies sold and updated number of Candies in JAR.
If Input is more than candies in JAR, return: "INVALID INPUT"
Given,
N=10, where N is NUMBER OF CANDIES AVAILABLE
K =< 5, where k is number of minimum candies that must be inside JAR ever.
Example 1:(N = 10, k =< 5)
Input Value
3
Output Value
NUMBER OF CANDIES SOLD: 3
NUMBER OF CANDIES AVAILABLE : 7
Example: (N=10, k<=5)
Input Value
0
Output Value
INVALID INPUT NUMBER OF
CANDIES LEFT: 10
C Code:
by TrustPulse
#include <stdio.h>
int main()
{
Transcribed Image Text:Coding Question / Question: There is a JAR full of candies for sale at a mall counter. JAR has the capacity N, that is JAR can contain maximum N candies when JAR is full. At any point of time. JAR can have M number of Candies where M<=N. Candies are served to the customers. JAR is never remain empty as when last k candies are left. JAR if refilled with new candies in such a way that JAR get full. Write a code to implement above scenario. Display JAR at counter with available number of candies. Input should be the number of candies one customer can order at point of time. Update the JAR after each purchase and display JAR at Counter. Output should give number of Candies sold and updated number of Candies in JAR. If Input is more than candies in JAR, return: "INVALID INPUT" Given, N=10, where N is NUMBER OF CANDIES AVAILABLE K =< 5, where k is number of minimum candies that must be inside JAR ever. Example 1:(N = 10, k =< 5) Input Value 3 Output Value NUMBER OF CANDIES SOLD: 3 NUMBER OF CANDIES AVAILABLE : 7 Example: (N=10, k<=5) Input Value 0 Output Value INVALID INPUT NUMBER OF CANDIES LEFT: 10 C Code: by TrustPulse #include <stdio.h> int main() {
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Maximum Flow
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education