Practice
Profit Calculator with Validation
2024/Feb/Mar·Variant 2
MEDIUMLoops
Continuously read pairs of cost price and selling price, calculate the profit (sell − cost), and output it. Repeat until both values are 0.
Both inputs must be validated to ensure they are 0 or greater (negative values are rejected).
The pair 0, 0 stops the algorithm without producing output.
Input: Alternating cost and sell prices.
Output: "Profit is X" for each valid non-exit pair.
Example:
Input: -5
10
15
0
0
Output: Profit is 5
Premium is coming soon. All grading features are currently unlocked.
Sample Test Cases
Test 1: Simple valid case
Inputs: 10, 15, 0, 0
Expected: Profit is 5
Test 2: Negative cost validation
Inputs: -5, 10, 12, 0, 0
Expected: Profit is 2
Ctrl+Enter
Press Ctrl+Enter to run your code
or Ctrl+Shift+Enter to grade