Advertisement
dragonbs

Computer Store

Feb 15th, 2023
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         double basePrice = 0;
  8.         string input = Console.ReadLine();
  9.         while (input != "special" && input != "regular")
  10.         {
  11.             double currentPrice = double.Parse(input);
  12.             if (currentPrice < 0)
  13.             {
  14.                 Console.WriteLine("Invalid price!");
  15.                 input = Console.ReadLine();
  16.                 continue;
  17.             }
  18.  
  19.             basePrice += currentPrice;
  20.             input = Console.ReadLine();
  21.         }
  22.  
  23.         if (basePrice == 0)
  24.         {
  25.             Console.WriteLine("Invalid order!");
  26.             return;
  27.         }
  28.  
  29.         double taxes = 0.2 * basePrice;
  30.         double total = basePrice + taxes;
  31.         if (input == "special") total *= 0.9;
  32.  
  33.         Console.WriteLine("Congratulations you've just bought a new computer!");
  34.         Console.WriteLine($"Price without taxes: {basePrice:f2}$");
  35.         Console.WriteLine($"Taxes: {taxes:f2}$");
  36.         Console.WriteLine("-----------");
  37.         Console.WriteLine($"Total price: {total:f2}$");
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement