7 kyu

Coding 3min : Hacker and change

Description:

Task:

John is a hacker, he always believed,"Knowledge can change the destiny".

He is ready to invade a supermarket checkout system. say concretely, his goal is the supermarket cash receipts and payments software.

The basic function of the software is:

Accept three parameters:

name, a string, customer name

items, an array, the price list of all the goods purchased by the customer. All elements in the array are numbers, up to two decimal places.

payment, a number, cash paid by customer

return a number, the change returned to customer, up to two decimal places. When the cash paid by the customer is insufficient, the return is negative.

John added a rule based on this:

When the customer name is "John"

If the result >0, the decimal portion is doubled.

for example:

change("John",[1.1,2.2,3.3],10)
John bought three pieces of goods, 
the total value is 1.1+2.2+3.3=6.6, payment is 10
The cashier should give John the change 3.4
But due to a "small fault", the change became 3+0.4*2=3.8

If the result <=0, return 0.

for example:

change("John",[11],10)
John bought one good=11, payment is 10, result=-1
It means John needs to give the cashier 1
But due to a "small fault", the change became 0
John doesn't need to pay the cashier

So John can save a lot of money, God bless the police will not catch him ;-)

Series:

Puzzles
Games

Stats:

CreatedApr 18, 2016
PublishedApr 18, 2016
Warriors Trained414
Total Skips7
Total Code Submissions911
Total Times Completed193
JavaScript Completions193
Total Stars9
% of votes with a positive feedback rating92% of 66
Total "Very Satisfied" Votes58
Total "Somewhat Satisfied" Votes5
Total "Not Satisfied" Votes3
Total Rank Assessments7
Average Assessed Rank
7 kyu
Highest Assessed Rank
7 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • smile67 Avatar
  • user9644768 Avatar
Ad