Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Program to caluclate the value of dirt depending on how many blocks a vendor has.
- Author: John Ginnane
- Date: 07 / 02 / 12
- */
- #include <stdio.h>
- main()
- {
- // Initialising the variables.
- float dirtValue = 10;
- // A value of 1 means the block is worth 1 copper.
- // 1 gold = 10 silver
- // 1 silver = 10 copper
- float dirtStock = 10000;
- float trade = 0;
- /*
- The mode determines one thing: How sales go.
- 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)
- 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.
- */
- int mode = 1;
- // Display the initial value and number of stock.
- printf("The initial value of dirt: %0.4f\n", dirtValue);
- printf("The initial number of stock: %0.2f\n\n", dirtStock);
- printf("Enter the number of blocks you want to sell\n");
- printf("Enter a negative number to buy and a positive one to sell\n");
- if(mode == 1)
- {
- while(dirtStock > 0 && dirtValue > 0)
- {
- // Ask the user to enter how many blocks they want to buy or sell.
- printf("How many blocks would you like to buy/sell: ");
- scanf("%f", &trade);
- if(trade > 0)
- {
- printf("You have sold %0.2f blocks worth a total of %0.4f copper.\n\n", trade, trade * dirtValue);
- }
- if(trade < 0)
- {
- printf("You have purchased %0.2f blocks worth a total of %0.4f copper.\n\n", -trade, trade * dirtValue);
- }
- if(trade == 0)
- {
- printf("No blocks have been sold nor purchased\n\n");
- }
- dirtValue = dirtValue * (dirtStock / (dirtStock + trade));
- dirtStock = dirtStock + trade;
- printf("The value of dirt is now: %0.4f\n", dirtValue);
- printf("The number of stock is now: %0.2f\n\n", dirtStock);
- }
- }
- }
Add Comment
Please, Sign In to add comment