Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 KB | None | 0 0
  1. Scenario
  2. 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.  
  3.  
  4. *   Accept the dollar value of each item purchased from the user until the user is finished.  
  5. *   When purchases are complete, enter a sentinel value of -1 (indicating that the user has finished).  
  6. *   If the item purchased is $50.00 or more, give your customer a 10% discount on the item purchased.  
  7. *   Display all of the purchases to the customer with the original price and the discount price.
  8.  
  9.  
  10. using System;
  11.  
  12. namespace MDoyle_W5_iLab
  13. {
  14.     class MainClass
  15.     {
  16.         public static void Main (string[] args)
  17.         {
  18.             int totalItems = 1;
  19.             double items = 0;
  20.             double itemCost = 0;
  21.             double discountTotal = 0;
  22.  
  23.             Console.WriteLine ("Enter Item Costs Bellow. \nType '-1' to end.\n");
  24.  
  25.        
  26.             while (items >= 0) {
  27.  
  28.                 Console.Write ("Enter Cost of Item {0}: ", totalItems);
  29.  
  30.                 while (!double.TryParse (Console.ReadLine (), out items)) {
  31.                     Console.WriteLine ("Enter a Valid Input");
  32.                     Console.Write ("Enter Cost of Item {0}: ", totalItems);
  33.                 }
  34.                    
  35.        
  36.                 if (items >= 50) {
  37.                     Console.WriteLine ("Price: ${0}", items);
  38.                     discountTotal = (items * .10) + discountTotal;
  39.                     items = items * .90;
  40.                     Console.WriteLine ("After Discount: ${0}\n", items);
  41.                     itemCost = items + itemCost;
  42.                     totalItems++;
  43.                 }
  44.                 else if (items > 0 && items < 50)
  45.                 {
  46.                     Console.WriteLine ("Price: ${0}\n", items);
  47.                     itemCost = items+itemCost;
  48.                     totalItems++;
  49.                 }
  50.                 else
  51.                 {
  52.                     items = -1;
  53.                 }
  54.            
  55.             }
  56.  
  57.             Console.WriteLine ("\nTotal Items Sold: {0}", (totalItems - 1));
  58.             Console.WriteLine ("Total Cost: ${0}", itemCost);
  59.  
  60.             if (discountTotal > 0) {
  61.                 Console.WriteLine ("You Saved ${0}", discountTotal);
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement