Teo_Yanchev

02. HelloFrance - C# Fundamentals EXAM G1 - 10.03.2019

Sep 27th, 2020
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02._HelloFrance
  6. {
  7. class HelloFrance
  8. {
  9. static void Main()
  10. {
  11. List<string> input = Console.ReadLine()
  12. .Split(new Char[] { '-', '>', '|' }, StringSplitOptions.RemoveEmptyEntries)
  13. .ToList();
  14. decimal budget = decimal.Parse(Console.ReadLine());
  15. List<decimal> newPrices = new List<decimal>();
  16. decimal profit = 0.00m;
  17.  
  18. for (int i = 0; i < input.Count; i += 2)
  19. {
  20. string product = input[i];
  21. decimal price = decimal.Parse(input[i + 1]);
  22.  
  23. bool dontBuyClothes = (product == "Clothes" && price > 50.00m) || (product == "Clothes" && budget < price);
  24. bool dontBuyShoes = (product == "Shoes" && price > 35.00m) || (product == "Shoes" && budget < price);
  25. bool dontBuyAccessories = (product == "Accessories" && price > 20.50m) || (product == "Accessories" && budget < price);
  26.  
  27. if (dontBuyClothes)
  28. {
  29. continue;
  30. }
  31. else if (dontBuyShoes)
  32. {
  33. continue;
  34. }
  35. else if (dontBuyAccessories)
  36. {
  37. continue;
  38. }
  39. else
  40. {
  41. decimal increasedPrice = 0.00m;
  42. budget -= price;
  43. increasedPrice = price * 1.40m;
  44. newPrices.Add(increasedPrice);
  45. profit += (increasedPrice - price);
  46. }
  47. }
  48.  
  49. for (int i = 0; i < newPrices.Count; i++)
  50. {
  51. string printPrice = $"{newPrices[i]:F2} ";
  52. Console.Write(printPrice);
  53. }
  54. Console.WriteLine();
  55. Console.WriteLine($"Profit: {profit:f2}");
  56. decimal total = newPrices.Sum() + budget;
  57.  
  58. if (total >= 150.00m)
  59. {
  60. Console.WriteLine("Hello, France!");
  61. }
  62. else
  63. {
  64. Console.WriteLine("Time to go.");
  65. }
  66. }
  67. }
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment