Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function reportSystem(input) {
- let finalAmout = Number(input.shift());
- let cashPayment = 0;
- let cardPayment = 0;
- let currentTransaction = Number(input.shift());
- let numOfCurrentTransaction = 0;
- let sum1 = 0;
- let sum2 = 0;
- let total = 0;
- let countCashPayment=0;
- let countCardPayment=0;
- while (finalAmout > total || currentTransaction === "End") {
- if (currentTransaction === "End") {
- console.log("Failed to collect required money for charity.");
- break;
- }
- if (numOfCurrentTransaction % 2 == 0) {
- cashPayment = Number(currentTransaction);
- if (cashPayment > 100) {
- console.log("Error in transaction!");
- } else {
- console.log("Product sold!");
- countCashPayment++;
- sum1 += cashPayment;
- }
- } else {
- cardPayment = Number(currentTransaction);
- if (cardPayment < 10) {
- console.log("Error in transaction!");
- } else {
- console.log("Product sold!");
- countCardPayment++
- sum2 += cardPayment;
- }
- }
- total = sum1 + sum2;
- numOfCurrentTransaction++;
- currentTransaction = input.shift();
- }
- if (total >= finalAmout) {
- console.log(`Average CS: ${(sum1 / countCashPayment).toFixed(2)}`);
- console.log(`Average CC: ${(sum2 / countCardPayment).toFixed(2)}`);
- }
- }
- reportSystem(
- [
- '500', '120',
- '8', '63',
- '256', '78',
- '317'
- ]
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement