Advertisement
Iskrenov84

Tax Calculator

Feb 20th, 2022
1,204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace ProblemTwoExam
  7. {
  8.     internal class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             List<string> myList = Console.ReadLine()
  13.                 .Split(">>",StringSplitOptions.RemoveEmptyEntries)
  14.                 .ToList();
  15.  
  16.             decimal tax = 0.00m;
  17.             decimal nationalRevenueAgency = 0.00m;
  18.  
  19.             for (int i = 0; i < myList.Count; i++)
  20.             {
  21.                 string[] tokens = myList[i].Split(' ');
  22.  
  23.                 switch (tokens[0])
  24.                 {
  25.                     case "family":
  26.                         tax = int.Parse(tokens[2]) / 3000  * 12 + (50 - int.Parse(tokens[1]) * 5);
  27.                         nationalRevenueAgency += tax;
  28.                         Console.WriteLine($"A {tokens[0]} car will pay {tax:f2} euros in taxes.");
  29.                         tax = 0.00m;
  30.                        break;
  31.                     case "heavyDuty":
  32.                         tax = int.Parse(tokens[2]) / 9000 * 14 + (80 - int.Parse(tokens[1]) * 8);
  33.                         nationalRevenueAgency += tax;
  34.                         Console.WriteLine($"A {tokens[0]} car will pay {tax:f2} euros in taxes.");
  35.                         tax = 0.00m;
  36.                         break;
  37.                     case "sports":
  38.                         tax = int.Parse(tokens[2]) / 2000 * 18 + (100 - int.Parse(tokens[1]) * 9);
  39.                         nationalRevenueAgency += tax;
  40.                         Console.WriteLine($"A {tokens[0]} car will pay {tax:f2} euros in taxes.");
  41.                         tax = 0.00m;
  42.                         break;
  43.                 }
  44.                 if (tokens[0] != "family" && tokens[0] != "heavyDuty" && tokens[0] != "sports")
  45.                 {
  46.                     Console.WriteLine("Invalid car type.");
  47.                 }
  48.             }
  49.             Console.WriteLine($"The National Revenue Agency will collect {nationalRevenueAgency:f2} euros in taxes.");
  50.         }
  51.     }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement