Цитата:
Цитата:
|
Цитата:
https://jsfiddle.net/KEMPZOR/64nnq1p9/ |
Цитата:
|
Цитата:
1 - 35 2 - 35 3 - 35 4 - 35 5 - 35 6 - 825 Последний такой должен быть 825. |
KEMPZOR,
алгоритм формирования чисел так и не понял, помочь не могу. |
Цитата:
0 - 50 1 - 50 2 - 0 3 - 0 4 - 0 5 - 0 6 - 0 0 - Это первый платёж, остальные по месяцам. |
Цитата:
0 - 160 1 - 160 2 - 160 3 - 160 4 - 160 5 - 160 6 - 40 Почему 160 и 40 ? 1000/6=166.6667 Наименьшее кратное будет 165. 165*6 = 990 1000-990=10 последний платёж (не менее 35), значит не подходит, уменьшаем ещё на 5. 160*6 = 960 1000-960=40 последний платёж (не менее 35), значит подходит. Помогите пожалуйста решить задачку, за мной не заржавеет (заплачу денежку). |
Сумма (кратная 5, не меньше 35):<input id="sum" type = "text" value = "1000"><br> <input type="button" value="Считать" onclick = "calc();"><br> <div id = "result"></div> <script> function calc() { var summa = +sum.value, period = 6; if(summa < 35 || Math.floor(summa / 5) * 5 != summa) { alert("Сумма должна быть кратной 5, не меньше 35"); result.innerHTML = ""; return; } var tempPay, currentPay, lastPay; tempPay = summa / period; currentPay = Math.floor(tempPay / 5) * 5; if (currentPay < 35) currentPay = 35; period = Math.round(summa / currentPay); currentPay = currentPay + 5; do { currentPay = currentPay - 5; lastPay = summa - currentPay * period; } while ( lastPay < 35 && lastPay != 0); if (currentPay < 35) { currentPay = 30; do { currentPay = currentPay + 5; period = Math.floor(summa / currentPay); lastPay = summa - currentPay * period; } while (lastPay != 0 && lastPay < 35); } result.innerHTML = ""; for (var i = 0; i < period; i++) { result.innerHTML += i + " - " + currentPay + "<br>"; } result.innerHTML += i + " - " + lastPay + "<br>"; } </script> Насчет денежки - пускай себе ржавеет, лучше пусти эти средства на изучение арифметики |
Цитата:
<script type="text/javascript" src="http://l-c.by/g/libs/jquery/1.10.2/jquery.min.js" <p>Сумма</p> <input id="sum" type = "text" value = ""> <p>Месяц</p> <select class="select-month" name="month"> <option value="2">1</option> <option value="3">2</option> <option value="4">3</option> <option value="5">4</option> <option value="6">5</option> <option value="7">6</option> </select> <input type="button" value="Считать" onclick = "calc();"><br> <div id = "result"></div> function calc() { var summa = +sum.value.replace(",", "."), period = parseInt($("select[name=month]").val()) , selperiod = period; if(summa < 35) { alert("Сумма должна быть кратной 5, не меньше 35"); result.innerHTML = ""; return; } var tempPay, currentPay, lastPay; tempPay = summa / period; /*if (summa <= 244) { tempPay = summa / 35; }*/ currentPay = Math.floor(tempPay / 5) * 5; if (currentPay < 35) currentPay = 35; currentPay = currentPay + 5; do { currentPay = currentPay - 5; lastPay = summa - currentPay * (period-1); } while ( lastPay < 35 && lastPay != 0); if (currentPay < 35) { currentPay = 30; do { currentPay = currentPay + 5; period = Math.round(summa / currentPay); lastPay = summa - currentPay * period; } while (lastPay != 0 && lastPay < 35); } result.innerHTML = ""; for (var i = 0; i < period-1; i++) { result.innerHTML += i + " - " + currentPay + "<br>"; } result.innerHTML += i + " - " + lastPay.toFixed(2) + "<br>"; } P.S. Арифметику подтяну, обещаю ))) |
KEMPZOR,
Цитата:
0 - 50 1 - 50 2 - 0 - это неправильно? Еще какие неправильно? Это условие соблюдается? Сумма должна быть кратной 5, не меньше 35 Или суммы бывают произвольные? Я это не предусматривал - платежи по месяцам кратные 5. Правда, попробовал, снял ограничение по кратности 5 - все считается правильно, даже с копейками. Ошибок не увидел. |
Часовой пояс GMT +3, время: 20:58. |