Advertisement
Filkolev

Book Orders - correction

Mar 22nd, 2015
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.39 KB | None | 0 0
  1. namespace BookOrders
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.  
  6.     public class BookOrders
  7.     {
  8.         public static void Main()
  9.         {
  10.             int n = int.Parse(Console.ReadLine());
  11.             var books = new List<double>();
  12.  
  13.             for (int i = 0; i < n * 3; i++)
  14.             {
  15.                 books.Add(double.Parse(Console.ReadLine()));
  16.             }
  17.  
  18.             double totalBooks = 0;
  19.             double totalPrice = 0;
  20.  
  21.             for (int i = 0; i < books.Count; i += 3)
  22.             {
  23.                 double tempBooks = books[i] * books[i + 1];
  24.                 double tempCost = GetDiscountedPrice(books, i);
  25.  
  26.                 double tempPrice = tempBooks * tempCost;
  27.                 totalPrice += tempPrice;
  28.  
  29.                 totalBooks += tempBooks;
  30.             }
  31.  
  32.             Console.WriteLine(totalBooks);
  33.             Console.WriteLine("{0:F2}", totalPrice);
  34.         }
  35.  
  36.         private static double GetDiscountedPrice(List<double> books, int i)
  37.         {
  38.             double tempCost = books[i + 2];
  39.  
  40.             if (books[i] >= 10 && books[i] <= 19)
  41.             {
  42.                 tempCost *= 0.95;
  43.             }
  44.             else if (books[i] >= 20 && books[i] <= 29)
  45.             {
  46.                 tempCost *= 0.94;
  47.             }
  48.             else if (books[i] >= 30 && books[i] <= 39)
  49.             {
  50.                 tempCost *= 0.93;
  51.             }
  52.             else if (books[i] >= 40 && books[i] <= 49)
  53.             {
  54.                 tempCost *= 0.92;
  55.             }
  56.             else if (books[i] >= 50 && books[i] <= 59)
  57.             {
  58.                 tempCost *= 0.91;
  59.             }
  60.             else if (books[i] >= 60 && books[i] <= 69)
  61.             {
  62.                 tempCost *= 0.9;
  63.             }
  64.             else if (books[i] >= 70 && books[i] <= 79)
  65.             {
  66.                 tempCost *= 0.89;
  67.             }
  68.             else if (books[i] >= 80 && books[i] <= 89)
  69.             {
  70.                 tempCost *= 0.88;
  71.             }
  72.             else if (books[i] >= 90 && books[i] <= 99)
  73.             {
  74.                 tempCost *= 0.87;
  75.             }
  76.             else if (books[i] >= 100 && books[i] <= 109)
  77.             {
  78.                 tempCost *= 0.86;
  79.             }
  80.             else if (books[i] >= 110)
  81.             {
  82.                 tempCost *= 0.85;
  83.             }
  84.  
  85.             return tempCost;
  86.         }
  87.     }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement