Disneyland Journey Programming Fundamentals Mid Exam Retake - 10 December 2019
Здравейте колеги,
не разбирам къде греша в тази задача - във vs си работи всичко - може ли малко помощ?
function solve(arg1, arg2) {
let savedMoney = 0;
let months = 1;
let journeyMoney = Number(arg1);
let numberOfmonths = Number(arg2);
while(months <= numberOfmonths){
if(months % 2 !== 0 && months !== 1){
savedMoney -= savedMoney * 0.16;
}
if(months % 4 == 0){
savedMoney += savedMoney * 0.25;
}
savedMoney += journeyMoney * 0.25;
months++;
}
if(savedMoney >= journeyMoney){
let money = (savedMoney - journeyMoney).toFixed(2);
console.log(`Bravo! You can go to Disneyland and you will have ${money}lv. for souvenirs.`);
}
else{
let money = (journeyMoney - savedMoney).toFixed(2);
console.log(`Sorry. You need ${money}lv. more.`);
}
}
solve(5000,
1)
;
Create a program that checks if you can save the money for the Disneyland’s journey. You have a certain number of months for which you can collect the money.
At the end of each month, you save 25% of the cost of the journey.
At the beginning of every odd month (except the first one) you spent 16% of the money collected so far for clothes and shoes.
Every 4th (fourth) month at the beginning of the month your boss gives you а bonus. It is 25% of the money collected so far.
If you save enough money for the journey, calculate how much money will be left for the souvenirs. Then print the following:
"Bravo! You can go to Disneyland and you will have {money}lv. for souvenirs."
If the saved money is less you should calculate how much money you need more. Then print the following:
"Sorry. You need {money}lv. more."
Both numbers should be formatted to the 2nd decimal place.
Input
- On the 1st line you will receive how much the journey will cost – a real number in the range [500.0…10000.0]
- On the 2nd line you will receive the number of months for which you have to collect money – an integer number in the range [1…12]
Output
- Print the output in the format described above.
Examples
Input |
Output |
1000 |
Bravo! You can go to Disneyland and you will have 87.50lv. for souvenirs. |
Comments |
|
You need 1000 leva for the journey and you have 4 months to collect them. Every month you can save 1000 * 25% => 250 lv. So, to the end of the 1st month you have 250 lv. To the end of the 2nd month - 250 + 250 -> 500 lv. To the begging of the 3th month (odd month) you spent 80 lv. (500 * 16%) for clothes and shoes, then you save 250 lv, so now you have 670 lv. Last month is the fourth month and you save 670 + 167.5 (670 * 25%) + 25 = 1087.5 lv. You have 1087.5 – 1000 = 87.5 lv., so you can go to the trip. |
|
|
|
3265 3 |
Sorry. You need 1077.45lv. more. |
добре. ок. обаче как този вход на данни да работи във vs и в judge ? и изобщо това в коя лекция го обясняват ? не мога да го разбера
Ако не знаеш как подават входните данни което се случва с всеки в javascript, правиш следното.
Отваряш judge където ти е задачата и пишеш console.log натискаш бутона submit за да изпратиш заявката
после натискаш кръглото бутонче за да се оцени и ще ти даде 0/100.
Отиваш на детайли и в дясната част където пише "Your output" в зелено ще видиш под каква форма подават входните данни!
И това е то относно проблема с входните данни в javascript
Някой да има за java basic?