Simple Fun #372: Lose Or Earn?
Description:
Problem
Businessmen, of course, can make much money. However, sometimes, they would lose money in trading.
For example, John, a businessman, brought in some goods each cost him $40
and he decided to sell at the price of $70
. Then a customer came to buy one, gave John $100
, and of course got back $30
.
You may said, "John earned $30
." But unfortunately, John found the $100
from the customer was fake. What a poor man!
In this case John lost his money :(
Now your task is to calculate how much John would lose in this kind of trade. Of course, sometimes John may still earn.
Task
You are given four arguments:
costPrice
: the cost price of John's good.sellPrice
: the sell price of John's good.fakeMoney
: the total fake money the customer gave John.paidBack
: how much John paid back to the customer.
Your result should be a string: If John loses money after the deal, return "Lost $xxx"
(xxx is the amount of money). Otherwise, return "Earned $xxx"
.
Still not understand the task? Look at the following example ;-)
Example
For costPrice = 40, sellPrice = 70, fakeMoney = 100, paidBack = 30
the output should be "Lost $70"
In this case John lost $70
: ($40
(the goods price) + $30
(the money paid back to the customer)).
For costPrice = 40, sellPrice = 70, fakeMoney = 50, paidBack = 20
the output should be "Lost $20"
In this case John lost $20
: John received $40 true money and $50
fake money, then paid back $20
true money to the customer. He has $20
true money left, but the cost price of good is $40
, so he lost $20
.
Note
0 < costPrice < sellPrice < 100000
0 <= fakeMoney < 100000
0 <= paidBack < 100000
Happy Coding
^_^
Similar Kata:
Stats:
Created | Oct 31, 2017 |
Published | Nov 1, 2017 |
Warriors Trained | 330 |
Total Skips | 10 |
Total Code Submissions | 494 |
Total Times Completed | 167 |
JavaScript Completions | 102 |
C# Completions | 73 |
Total Stars | 6 |
% of votes with a positive feedback rating | 76% of 61 |
Total "Very Satisfied" Votes | 40 |
Total "Somewhat Satisfied" Votes | 13 |
Total "Not Satisfied" Votes | 8 |
Total Rank Assessments | 3 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 7 kyu |
Lowest Assessed Rank | 8 kyu |