Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Computer_Science_Pre_Release {
- class Program {
- static void Main(string[] args) {
- //declare the variable
- string[,] items;
- //amount of items
- int itemcount;
- //out of stock counter
- int itemsleft;
- //ask for amount of items sold
- Console.WriteLine("How many items would you like to sell today?");
- while (!int.TryParse(Console.ReadLine(), out itemcount) && itemcount <= 0) {
- Console.WriteLine("Please enter a valid number!");
- }
- // set itemsleft to itemcount
- itemsleft = itemcount;
- // add item number, description, reserve price
- items = new string[itemcount, 3];
- // loop over every item
- for (var i = 0; i < itemcount; i++) {
- Console.WriteLine("Please add a description to your item");
- items[i, 0] = Console.ReadLine();
- Console.WriteLine("What is the reserve price of your item?");
- int reserve;
- while (int.TryParse(Console.ReadLine(), out reserve) && reserve <= 0) {
- Console.WriteLine("Please enter a valid number!");
- }
- // set item reserve
- items[i, 1] = reserve.ToString();
- }
- // while items are left to be sold
- while (itemsleft > 0) {
- try {
- // item id
- int item;
- // min bid
- int minbid;
- // userbid
- int userbid;
- // currentbid
- int currentbid;
- // final price with 10%
- decimal finalprice;
- Console.WriteLine("What product would you like to bid on?");
- while (!int.TryParse(Console.ReadLine(), out item) && item < 0 && item > itemcount - 1) {
- Console.WriteLine("Please enter a valid number!");
- }
- Console.WriteLine("Item Description :" + Environment.NewLine + items[item, 0]);
- Console.WriteLine("Reserve Price:" + Environment.NewLine + items[item, 1]);
- minbid = int.Parse(items[item, 1]); // no check as number is valid from before
- if (!int.TryParse(items[item, 2], out currentbid))
- currentbid = 0;
- Console.WriteLine("Current Bid: " + currentbid);
- Console.WriteLine("What is your bid?");
- while (!int.TryParse(Console.ReadLine(), out userbid)) {
- Console.WriteLine("Please enter a valid bid!");
- }
- if (userbid >= minbid) {
- Console.WriteLine("Sold!");
- finalprice = Convert.ToDecimal(userbid * 1.1);
- Console.WriteLine("Price with fees: " + finalprice);
- itemsleft -= 1;
- }
- else if (userbid > currentbid) {
- Console.WriteLine("Bid Sucessfull!");
- items[item, 2] = userbid.ToString();
- }
- //bid too low
- else {
- Console.WriteLine("Your bid is too low!");
- }
- }
- //unknown error
- catch {
- Console.WriteLine("An unknown error occured!");
- }
- }
- Console.WriteLine("Auction complete!");
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement