nikolayneykov

Untitled

Mar 26th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.55 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _1grupa_SpringVacationTrip
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int days = int.Parse(Console.ReadLine());
  10.             double budget = double.Parse(Console.ReadLine());
  11.             int people = int.Parse(Console.ReadLine());
  12.             double fuelPrice = double.Parse(Console.ReadLine());
  13.             double foodPrice = double.Parse(Console.ReadLine());
  14.             double roomPrice = double.Parse(Console.ReadLine());
  15.             double hotelExpenses = roomPrice * people * days;   //предварително изчисляваме цената за разходите
  16.             double foodExpenses = foodPrice * people * days;    //на хотела и на храната
  17.             double totalExpenses = 0;
  18.  
  19.             if (people > 10)
  20.             {
  21.                 hotelExpenses = 0.75 * hotelExpenses;
  22.             }
  23.  
  24.             totalExpenses = hotelExpenses + foodExpenses;   //сумираме преди да сме влезли в цикъла
  25.          
  26.             for (int i = 1; i <= days; i++)
  27.             {
  28.                 if (totalExpenses > budget) //в началото на деня проверяваме дали не сме надхвърлили бюджета (заради предварителното изчисляване на горните разходи)
  29.                 {
  30.                     break;
  31.                 }
  32.                 double travelExpenses = fuelPrice * double.Parse(Console.ReadLine());   //изчисляваме цената за гориво за настоящия ден
  33.                 totalExpenses += travelExpenses;    //добавяме само цената за гориво
  34.  
  35.                 if (i % 3 == 0 || i % 5 == 0)   //на всеки 3-ти и 5-ти ден увеличаваме разходите с 40%
  36.                 {
  37.                     totalExpenses *= 1.4;
  38.                 }
  39.  
  40.                 if (i % 7 == 0) //на всеки 7-ми ден редуцираме цената
  41.                 {
  42.                     totalExpenses -= totalExpenses / people;
  43.                 }
  44.  
  45.             }
  46.  
  47.             if (totalExpenses > budget)
  48.             {
  49.                 Console.WriteLine($"Not enough money to continue the trip. You need {totalExpenses - budget:f2}$ more.");
  50.  
  51.             }
  52.             else if (totalExpenses <= budget)
  53.             {
  54.                 Console.WriteLine($"You have reached the destination. You have {budget - totalExpenses:f2}$ budget left.");
  55.             }
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment