Advertisement
Dimitar46

Computer Store

May 31st, 2022
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using System;
  2.  
  3. namespace MidExamComputerStoreExercise1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string command = Console.ReadLine();
  10.             double priceWithoutTax = 0;
  11.             while(command != "regular" && command != "special")
  12.             {
  13.  
  14.                 double price = double.Parse(command);
  15.                 if (price < 0)
  16.                 {
  17.                     Console.WriteLine("Invalid price!");
  18.                     command = Console.ReadLine();
  19.                     continue;
  20.                 }
  21.                 priceWithoutTax += price;
  22.                 command = Console.ReadLine();
  23.             }
  24.             if (priceWithoutTax == 0)
  25.             {
  26.                 Console.WriteLine("Invalid order!");
  27.                 return;
  28.             }
  29.            
  30.             double taxes = 0.20 * priceWithoutTax;
  31.             double allPrice = priceWithoutTax + taxes;
  32.             if(command == "special")
  33.             {
  34.                 allPrice = allPrice - allPrice* 0.10;
  35.             }
  36.             Console.WriteLine($"Congratulations you've just bought a new computer!\nPrice without taxes: {priceWithoutTax:F2}$\nTaxes: {taxes:F2}$\n-----------\nTotal price: {allPrice:F2}$");
  37.         }
  38.     }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement