Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Computer_Science_Pre_Release {
  8.     class Program {
  9.         static void Main(string[] args) {
  10.             //declare the variable
  11.             string[,] items;
  12.            
  13.             //amount of items
  14.             int itemcount;
  15.             //out of stock counter
  16.             int itemsleft;
  17.  
  18.             //ask for amount of items sold
  19.             Console.WriteLine("How many items would you like to sell today?");
  20.  
  21.             while (!int.TryParse(Console.ReadLine(), out itemcount) && itemcount <= 0) {
  22.                 Console.WriteLine("Please enter a valid number!");
  23.             }
  24.  
  25.             // set itemsleft to itemcount
  26.             itemsleft = itemcount;
  27.  
  28.             // add item number, description, reserve price
  29.             items = new string[itemcount, 3];
  30.  
  31.             // loop over every item
  32.             for (var i = 0; i < itemcount; i++) {
  33.                 Console.WriteLine("Please add a description to your item");
  34.                 items[i, 0] = Console.ReadLine();
  35.  
  36.                 Console.WriteLine("What is the reserve price of your item?");
  37.  
  38.                 int reserve;
  39.                 while (int.TryParse(Console.ReadLine(), out reserve) && reserve <= 0) {
  40.                     Console.WriteLine("Please enter a valid number!");
  41.                 }
  42.  
  43.                 // set item reserve
  44.                 items[i, 1] = reserve.ToString();
  45.             }
  46.  
  47.             // while items are left to be sold
  48.             while (itemsleft > 0) {
  49.                 try {
  50.                     // item id
  51.                     int item;
  52.                     // min bid
  53.                     int minbid;
  54.                     // userbid
  55.                     int userbid;
  56.                     // currentbid
  57.                     int currentbid;
  58.                     // final price with 10%
  59.                     decimal finalprice;
  60.  
  61.                     Console.WriteLine("What product would you like to bid on?");
  62.  
  63.                     while (!int.TryParse(Console.ReadLine(), out item) && item < 0 && item > itemcount - 1) {
  64.                         Console.WriteLine("Please enter a valid number!");
  65.                     }
  66.  
  67.                     Console.WriteLine("Item Description :" + Environment.NewLine + items[item, 0]);
  68.                     Console.WriteLine("Reserve Price:" + Environment.NewLine + items[item, 1]);
  69.  
  70.                     minbid = int.Parse(items[item, 1]); // no check as number is valid from before
  71.  
  72.                     if (!int.TryParse(items[item, 2], out currentbid))
  73.                         currentbid = 0;
  74.  
  75.                     Console.WriteLine("Current Bid: " + currentbid);
  76.                     Console.WriteLine("What is your bid?");
  77.  
  78.                     while (!int.TryParse(Console.ReadLine(), out userbid)) {
  79.                         Console.WriteLine("Please enter a valid bid!");
  80.                     }
  81.  
  82.                     if (userbid >= minbid) {
  83.                         Console.WriteLine("Sold!");
  84.                         finalprice = Convert.ToDecimal(userbid * 1.1);
  85.                         Console.WriteLine("Price with fees: " + finalprice);
  86.                         itemsleft -= 1;
  87.                     }
  88.                     else if (userbid > currentbid) {
  89.                         Console.WriteLine("Bid Sucessfull!");
  90.                         items[item, 2] = userbid.ToString();
  91.                     }
  92.                     //bid too low
  93.                     else {
  94.                         Console.WriteLine("Your bid is too low!");
  95.                     }
  96.                 }
  97.                 //unknown error
  98.                 catch {
  99.                     Console.WriteLine("An unknown error occured!");
  100.                 }
  101.             }
  102.  
  103.             Console.WriteLine("Auction complete!");
  104.             Console.ReadLine();
  105.         }
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement