Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Spring Vacation Trip
- A group of friends decide to go to a trip for a few days during spring vacation. They have a certain budget. Your task is to calculate their expenses during the trip and find out if they are going to have enough money to finish the vacation.
- Create a program that calculates travelling expenses by entering the following information:
- - Days of the vacation
- - Budget - its for the whole group
- - The count of people
- - Fuel per kilometer – the price for fuel that their car consumes per kilometer
- - Food expenses per person
- - Hotel room price for one night – again, for one person
- If the group is bigger than 10, they receive a 25% discount from the total hotel expenses.
- Every day, they travel some distance and you have to calculate the expenses for the travelled kilometers.
- Every third and fifth day, they have some additional expenses, which are 40% of the current value of the expenses.
- Every seventh day, their expenses are reduced, because they withdraw (receive) a small amount of money – you can calculate it by dividing the amount of the current expenses by the group of people.
- If the expenses exceed the budget at some point, stop calculating and print the following message:
- "Not enough money to continue the trip"
- If the budget is enough:
- "You have reached the destination. You have {money}$ budget left."
- Print the result formatted 2 digits after the decimal separator.
- Input / Constraints
- • On the 1st line, you are going to receive the days of the trip – an integer in the range [1…100]
- • On the 2nd line – the budget – a real number in the range [0.00 – 1000000.00]
- • On the 3rd line - the group of people – an integer in the rang [1 - 50]
- • On the 4th line – the price for fuel per kilometer – a real number [0.00 – 20.00]
- • On the 5th line – food expenses per person for a day – a real number [0.00 – 50.00]
- • On the 6th line – the price for a room for one night per person – a real number [0.00 – 1000.00]
- • On the next n lines – one for each of the days – the travelled distance in kilometers per day– a real number in the range [0.00 - 1000]
- Output
- • "Not enough money to continue the trip. You need {money}$ more." –
- if the budget is not enough
- • "You have reached the destination. You have {money}$ budget left." – if it’s enough.
- Print the result formatted 2 digits after the decimal separator.
- Examples
- Input Output Comments
- 7 We receive the days of the vacation, the budget, the group, the consumed fuel per
- 12000 You have reached the destination. kilometer, the food expenses and the price for a hotel room for one night.
- 5 You have 5083.48$ budget left. We must calclate the food expenses: 10 * 5 * 7 = 350
- 1.5 And the price for the hotel for all of the nights: 20 * 5 * 7 = 700
- 10 The curent expenses are 1050. For each day, we have to calculate the consumed
- 20 fuel – {travelledDistance} * 1.5 On every 3rd and 5th day we add the additional expenses:
- 512 0.4 * {currentExpenses} On every 7th day, they receive some money:{currentExpense} /{groupOfPeople}
- 318 After we have added the fuel expenses for each day and made the other calculations,
- 202 the expenses have reached 8645.652. When we divide them by the group (5),
- 154 the result is 1729.1304, so we have to reduce the expenses by that sum.
- 222 The expenses become 6916.5216. The budget is enough, so the result is:
- 108 "You have reached the destination. You have 5083.48$ budget left."
- 123
- 10 Not enough money to continue the trip. You need 465.79$ more.
- 20500
- 11
- 1.2
- 8
- 13
- 100
- 150
- 500
- 400
- 600
- 130
- 300
- 350
- 200
- 300
- using System;
- public class Program
- {
- public static void Main()
- {
- var daysOfTheTrip = int.Parse(Console.ReadLine());
- var theBudget = double.Parse(Console.ReadLine());
- var theGroupOfPeople = int.Parse(Console.ReadLine());
- var priceFuelKm = double.Parse(Console.ReadLine());
- var foodPersonDay = double.Parse(Console.ReadLine());
- var priceRoomNightPerson = double.Parse(Console.ReadLine());
- if (theBudget == 0)
- {
- return;
- }
- var foodExpenses = daysOfTheTrip * foodPersonDay * theGroupOfPeople;
- var priceHotel = priceRoomNightPerson * theGroupOfPeople * daysOfTheTrip;
- if (theGroupOfPeople > 10)
- {
- priceHotel *= 0.75; //Или priceHotel -= 0.25 * priceHotel;
- }
- var expenses = foodExpenses + priceHotel;
- for (int i = 1; i <= daysOfTheTrip; i++)
- {
- var travelledDistanceKmDay = double.Parse(Console.ReadLine());
- var expensesFuel = travelledDistanceKmDay * priceFuelKm;
- expenses += expensesFuel;
- if (i % 3 == 0 || i % 5 == 0) //Капанче! Така на 15-ия ден ще има само веднъж разходи!
- {
- expenses += 0.40 * expenses;
- }
- if (i % 7 == 0)
- {
- expenses -= expenses / theGroupOfPeople;
- }
- if (theBudget < expenses)
- {
- Console.WriteLine($"Not enough money to continue the trip. You need {expenses - theBudget:F2}$ more.");
- break;
- }
- else if (daysOfTheTrip == i)
- {
- Console.WriteLine($"You have reached the destination. You have {theBudget - expenses:F2}$ budget left.");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment