Teo_Yanchev

C# Funadamentals - 01. ComputerStore - MidExam 12.08.2020

Oct 23rd, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5. class ComputerStore
  6. {
  7. static void Main(string[] args)
  8. {
  9. double totalPrice = 0.00;
  10. double tax = 0.00;
  11. string command = Console.ReadLine();
  12. while (true)
  13. {
  14. if (command == "special" || command == "regular")
  15. {
  16. break;
  17. }
  18. double price = double.Parse(command);
  19. if (price < 0)
  20. {
  21. Console.WriteLine("Invalid price!");
  22. command = Console.ReadLine();
  23. continue;
  24. }
  25.  
  26. else
  27. {
  28. totalPrice += price;
  29. tax += (price * 0.20);
  30. }
  31.  
  32. command = Console.ReadLine();
  33. }
  34.  
  35. if (totalPrice == 0)
  36. {
  37. Console.WriteLine("Invalid order!");
  38. return;
  39. }
  40. double printPrice = totalPrice;
  41.  
  42. if (command == "special")
  43. {
  44. totalPrice = (totalPrice + tax) * 0.90;
  45. }
  46. else
  47. {
  48. totalPrice += tax;
  49. }
  50.  
  51. Console.WriteLine("Congratulations you've just bought a new computer!");
  52. Console.WriteLine($"Price without taxes: {printPrice:f2}$");
  53. Console.WriteLine($"Taxes: {tax:f2}$");
  54. Console.WriteLine("-----------");
  55. Console.WriteLine($"Total price: {totalPrice:f2}$");
  56. }
  57. }
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment