Guest User

Untitled

a guest
Jun 18th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. /*
  2. Program to caluclate the value of dirt depending on how many blocks a vendor has.
  3.  
  4. Author: John Ginnane
  5. Date: 07 / 02 / 12
  6. */
  7.  
  8. #include <stdio.h>
  9.  
  10. main()
  11. {
  12. // Initialising the variables.
  13. float dirtValue = 10;
  14. // A value of 1 means the block is worth 1 copper.
  15. // 1 gold = 10 silver
  16. // 1 silver = 10 copper
  17.  
  18. float dirtStock = 10000;
  19.  
  20. float trade = 0;
  21.  
  22. /*
  23. The mode determines one thing: How sales go.
  24. If mode 1 then if you sell 100 blocks, the value goes down by 1% in total and you earn 5,000 copper. (50 gold)
  25. If mode 2 then if you sell 100 blocks, the value goes down as if you sold 1 block, but repeated 100 times so it decreases after each block, even if it's a single sale.
  26. */
  27.  
  28. int mode = 1;
  29.  
  30. // Display the initial value and number of stock.
  31. printf("The initial value of dirt: %0.4f\n", dirtValue);
  32. printf("The initial number of stock: %0.2f\n\n", dirtStock);
  33. printf("Enter the number of blocks you want to sell\n");
  34. printf("Enter a negative number to buy and a positive one to sell\n");
  35.  
  36. if(mode == 1)
  37. {
  38. while(dirtStock > 0 && dirtValue > 0)
  39. {
  40. // Ask the user to enter how many blocks they want to buy or sell.
  41. printf("How many blocks would you like to buy/sell: ");
  42. scanf("%f", &trade);
  43.  
  44. if(trade > 0)
  45. {
  46. printf("You have sold %0.2f blocks worth a total of %0.4f copper.\n\n", trade, trade * dirtValue);
  47. }
  48.  
  49. if(trade < 0)
  50. {
  51. printf("You have purchased %0.2f blocks worth a total of %0.4f copper.\n\n", -trade, trade * dirtValue);
  52. }
  53.  
  54. if(trade == 0)
  55. {
  56. printf("No blocks have been sold nor purchased\n\n");
  57. }
  58.  
  59. dirtValue = dirtValue * (dirtStock / (dirtStock + trade));
  60. dirtStock = dirtStock + trade;
  61.  
  62. printf("The value of dirt is now: %0.4f\n", dirtValue);
  63. printf("The number of stock is now: %0.2f\n\n", dirtStock);
  64. }
  65. }
  66. }
Add Comment
Please, Sign In to add comment