Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.80 KB | None | 0 0
  1. //Program by André Davis 20191003
  2.  
  3. using System;
  4.  
  5. namespace Lab6
  6. {
  7. public class Program
  8. {
  9. public static void Main(string[] args)
  10. {
  11. /* Declare variables
  12. Five Items:
  13. Read in the quantity ordered, an integer
  14. Read in the item name, a string
  15. Read in the item price, a decimal
  16. */
  17. string userInput;
  18.  
  19. int quanityOrdered1;
  20. string itemName1;
  21. decimal itemPrice1;
  22.  
  23. int quanityOrdered2;
  24. string itemName2;
  25. decimal itemPrice2;
  26.  
  27. int quanityOrdered3;
  28. string itemName3;
  29. decimal itemPrice3;
  30.  
  31. int quanityOrdered4;
  32. string itemName4;
  33. decimal itemPrice4;
  34.  
  35. int quanityOrdered5;
  36. string itemName5;
  37. decimal itemPrice5;
  38.  
  39. //Get input from user
  40.  
  41. //Get Item 1
  42. Console.WriteLine("Enter Item Quantity: ");
  43. userInput = Console.ReadLine();
  44. int.TryParse(userInput, out quanityOrdered1);
  45.  
  46. Console.WriteLine("Enter Item Name: ");
  47. userInput = Console.ReadLine();
  48. itemName1 = userInput;
  49.  
  50. Console.WriteLine("Enter Item Price: ");
  51. userInput = Console.ReadLine();
  52. decimal.TryParse(userInput, out itemPrice1);
  53.  
  54. //Get Item 2
  55. Console.WriteLine("Enter Item Quantity: ");
  56. userInput = Console.ReadLine();
  57. int.TryParse(userInput, out quanityOrdered2);
  58.  
  59. Console.WriteLine("Enter Item Name: ");
  60. userInput = Console.ReadLine();
  61. itemName2 = userInput;
  62.  
  63. Console.WriteLine("Enter Item Price: ");
  64. userInput = Console.ReadLine();
  65. decimal.TryParse(userInput, out itemPrice2);
  66.  
  67. //Get Item 3
  68. Console.WriteLine("Enter Item Quantity: ");
  69. userInput = Console.ReadLine();
  70. int.TryParse(userInput, out quanityOrdered3);
  71.  
  72. Console.WriteLine("Enter Item Name: ");
  73. userInput = Console.ReadLine();
  74. itemName3 = userInput;
  75.  
  76. Console.WriteLine("Enter Item Price: ");
  77. userInput = Console.ReadLine();
  78. decimal.TryParse(userInput, out itemPrice3);
  79.  
  80. //Get Item 4
  81. Console.WriteLine("Enter Item Quantity: ");
  82. userInput = Console.ReadLine();
  83. int.TryParse(userInput, out quanityOrdered4);
  84.  
  85. Console.WriteLine("Enter Item Name: ");
  86. userInput = Console.ReadLine();
  87. itemName4 = userInput;
  88.  
  89. Console.WriteLine("Enter Item Price: ");
  90. userInput = Console.ReadLine();
  91. decimal.TryParse(userInput, out itemPrice4);
  92.  
  93. //Get Item 5
  94. Console.WriteLine("Enter Item Quantity: ");
  95. userInput = Console.ReadLine();
  96. int.TryParse(userInput, out quanityOrdered5);
  97.  
  98. Console.WriteLine("Enter Item Name: ");
  99. userInput = Console.ReadLine();
  100. itemName5 = userInput;
  101.  
  102. Console.WriteLine("Enter Item Price: ");
  103. userInput = Console.ReadLine();
  104. decimal.TryParse(userInput, out itemPrice5);
  105.  
  106.  
  107. //Calculations
  108.  
  109. //Step a - Calculate and output the total price of the order before any discount ("Subtotal")
  110. decimal subTotal = (quanityOrdered1 * itemPrice1) + (quanityOrdered2 * itemPrice2)
  111. + (quanityOrdered3 * itemPrice3) + (quanityOrdered4 * itemPrice4)
  112. + (quanityOrdered5 * itemPrice5);
  113.  
  114. Console.WriteLine("Subtotal: $" + subTotal);
  115.  
  116. /* Step b - Calculate and out the discount percentage based on the values from input.
  117. Discount Calculation Rules:
  118. i. If the customer orders more than 12 items total, they get a 10% discount
  119. ii. If the customer orders more than $50 worth of items, they get a 15% discount (Reuse Subtotal from a)
  120. iii. If the customer orders an item named "Pineapple Fritter", they get a 20% discount
  121. The || operator can make this easier, but you can do this with several single-conditional if statements if you prefer
  122. iv. If none of these apply, the discount is 0%
  123. */
  124.  
  125. decimal discountPercent = 0.0m; //Start with 0% discount, also fulfills Discount step iv, if no if-statement trigger a discount
  126. int totalItems = quanityOrdered1 + quanityOrdered2 + quanityOrdered3 + quanityOrdered4 + quanityOrdered5;
  127.  
  128. //Discount step i
  129. if (totalItems > 12)
  130. discountPercent = 0.10m; //Set discount to 10%
  131.  
  132. //Discount step ii
  133. if (subTotal > 50.0m)
  134. discountPercent = 0.15m; //Set discount to 15%
  135.  
  136. //Discount step iii
  137. string fritter = "Pineapple Fritter";
  138. if (itemName1 == fritter
  139. || itemName2 == fritter
  140. || itemName3 == fritter
  141. || itemName4 == fritter
  142. || itemName5 == fritter)
  143. discountPercent = .20m; //Set discount to 20, notice here if you use postfix m, you're allowed to do .20 and omit the 0 before decimal point.
  144.  
  145. Console.WriteLine("Discount: " + discountPercent * 100 + "%");
  146.  
  147. //Step c - Calculate and output the price after discount is subtracted ("Total")
  148. decimal total = subTotal - (subTotal * discountPercent);
  149. Console.WriteLine("Total: $" + total);
  150.  
  151.  
  152. //Keep console window open.
  153. Console.WriteLine(); //Create empty space.
  154. Console.WriteLine("Press any key to exit...");
  155. Console.ReadLine();
  156. }
  157. }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement