Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Program by André Davis 20191003
- using System;
- namespace Lab6
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- /* Declare variables
- Five Items:
- Read in the quantity ordered, an integer
- Read in the item name, a string
- Read in the item price, a decimal
- */
- string userInput;
- int quanityOrdered1;
- string itemName1;
- decimal itemPrice1;
- int quanityOrdered2;
- string itemName2;
- decimal itemPrice2;
- int quanityOrdered3;
- string itemName3;
- decimal itemPrice3;
- int quanityOrdered4;
- string itemName4;
- decimal itemPrice4;
- int quanityOrdered5;
- string itemName5;
- decimal itemPrice5;
- //Get input from user
- //Get Item 1
- Console.WriteLine("Enter Item Quantity: ");
- userInput = Console.ReadLine();
- int.TryParse(userInput, out quanityOrdered1);
- Console.WriteLine("Enter Item Name: ");
- userInput = Console.ReadLine();
- itemName1 = userInput;
- Console.WriteLine("Enter Item Price: ");
- userInput = Console.ReadLine();
- decimal.TryParse(userInput, out itemPrice1);
- //Get Item 2
- Console.WriteLine("Enter Item Quantity: ");
- userInput = Console.ReadLine();
- int.TryParse(userInput, out quanityOrdered2);
- Console.WriteLine("Enter Item Name: ");
- userInput = Console.ReadLine();
- itemName2 = userInput;
- Console.WriteLine("Enter Item Price: ");
- userInput = Console.ReadLine();
- decimal.TryParse(userInput, out itemPrice2);
- //Get Item 3
- Console.WriteLine("Enter Item Quantity: ");
- userInput = Console.ReadLine();
- int.TryParse(userInput, out quanityOrdered3);
- Console.WriteLine("Enter Item Name: ");
- userInput = Console.ReadLine();
- itemName3 = userInput;
- Console.WriteLine("Enter Item Price: ");
- userInput = Console.ReadLine();
- decimal.TryParse(userInput, out itemPrice3);
- //Get Item 4
- Console.WriteLine("Enter Item Quantity: ");
- userInput = Console.ReadLine();
- int.TryParse(userInput, out quanityOrdered4);
- Console.WriteLine("Enter Item Name: ");
- userInput = Console.ReadLine();
- itemName4 = userInput;
- Console.WriteLine("Enter Item Price: ");
- userInput = Console.ReadLine();
- decimal.TryParse(userInput, out itemPrice4);
- //Get Item 5
- Console.WriteLine("Enter Item Quantity: ");
- userInput = Console.ReadLine();
- int.TryParse(userInput, out quanityOrdered5);
- Console.WriteLine("Enter Item Name: ");
- userInput = Console.ReadLine();
- itemName5 = userInput;
- Console.WriteLine("Enter Item Price: ");
- userInput = Console.ReadLine();
- decimal.TryParse(userInput, out itemPrice5);
- //Calculations
- //Step a - Calculate and output the total price of the order before any discount ("Subtotal")
- decimal subTotal = (quanityOrdered1 * itemPrice1) + (quanityOrdered2 * itemPrice2)
- + (quanityOrdered3 * itemPrice3) + (quanityOrdered4 * itemPrice4)
- + (quanityOrdered5 * itemPrice5);
- Console.WriteLine("Subtotal: $" + subTotal);
- /* Step b - Calculate and out the discount percentage based on the values from input.
- Discount Calculation Rules:
- i. If the customer orders more than 12 items total, they get a 10% discount
- ii. If the customer orders more than $50 worth of items, they get a 15% discount (Reuse Subtotal from a)
- iii. If the customer orders an item named "Pineapple Fritter", they get a 20% discount
- The || operator can make this easier, but you can do this with several single-conditional if statements if you prefer
- iv. If none of these apply, the discount is 0%
- */
- decimal discountPercent = 0.0m; //Start with 0% discount, also fulfills Discount step iv, if no if-statement trigger a discount
- int totalItems = quanityOrdered1 + quanityOrdered2 + quanityOrdered3 + quanityOrdered4 + quanityOrdered5;
- //Discount step i
- if (totalItems > 12)
- discountPercent = 0.10m; //Set discount to 10%
- //Discount step ii
- if (subTotal > 50.0m)
- discountPercent = 0.15m; //Set discount to 15%
- //Discount step iii
- string fritter = "Pineapple Fritter";
- if (itemName1 == fritter
- || itemName2 == fritter
- || itemName3 == fritter
- || itemName4 == fritter
- || itemName5 == fritter)
- 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.
- Console.WriteLine("Discount: " + discountPercent * 100 + "%");
- //Step c - Calculate and output the price after discount is subtracted ("Total")
- decimal total = subTotal - (subTotal * discountPercent);
- Console.WriteLine("Total: $" + total);
- //Keep console window open.
- Console.WriteLine(); //Create empty space.
- Console.WriteLine("Press any key to exit...");
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement