Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Scenario
- Your algorithm will keep track of a customer’s purchases at the local fireworks stand. Customers will not know exactly how many items they will purchase, so using a For loop on this lab is not allowed. Let’s keep the rules simple.
- * Accept the dollar value of each item purchased from the user until the user is finished.
- * When purchases are complete, enter a sentinel value of -1 (indicating that the user has finished).
- * If the item purchased is $50.00 or more, give your customer a 10% discount on the item purchased.
- * Display all of the purchases to the customer with the original price and the discount price.
- using System;
- namespace MDoyle_W5_iLab
- {
- class MainClass
- {
- public static void Main (string[] args)
- {
- int totalItems = 1;
- double items = 0;
- double itemCost = 0;
- double discountTotal = 0;
- Console.WriteLine ("Enter Item Costs Bellow. \nType '-1' to end.\n");
- while (items >= 0) {
- Console.Write ("Enter Cost of Item {0}: ", totalItems);
- while (!double.TryParse (Console.ReadLine (), out items)) {
- Console.WriteLine ("Enter a Valid Input");
- Console.Write ("Enter Cost of Item {0}: ", totalItems);
- }
- if (items >= 50) {
- Console.WriteLine ("Price: ${0}", items);
- discountTotal = (items * .10) + discountTotal;
- items = items * .90;
- Console.WriteLine ("After Discount: ${0}\n", items);
- itemCost = items + itemCost;
- totalItems++;
- }
- else if (items > 0 && items < 50)
- {
- Console.WriteLine ("Price: ${0}\n", items);
- itemCost = items+itemCost;
- totalItems++;
- }
- else
- {
- items = -1;
- }
- }
- Console.WriteLine ("\nTotal Items Sold: {0}", (totalItems - 1));
- Console.WriteLine ("Total Cost: ${0}", itemCost);
- if (discountTotal > 0) {
- Console.WriteLine ("You Saved ${0}", discountTotal);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement