Practice
Bread Rolls Stock Tracker
2022/Oct/Nov·Variant 1
MEDIUMLoops
A bakery needs a program to make sure there are always enough fresh bread rolls available. The bakery starts with a stock of 50 bread rolls. The program should repeatedly take in the number of rolls sold until a value of -1 is entered.
Whenever the stock falls below 20, the program should output "Add new stock" and add 50 to the current stock. When -1 is entered, the program should stop and output the total number of rolls sold.
Input: A sequence of integers representing rolls sold, ending with -1. Output: "Add new stock" each time stock drops below 20, then the total rolls sold at the end.
Example:
Input: 24
12
-1
Output: Add new stock
36
Premium is coming soon. All grading features are currently unlocked.
Sample Test Cases
Test 1: One restock triggered
Inputs: 24, 12, -1
Expected: Add new stock
36
Test 2: No restocking needed
Inputs: 5, 5, 5, -1
Expected: 15
Ctrl+Enter
Press Ctrl+Enter to run your code
or Ctrl+Shift+Enter to grade