Guest User

Untitled

a guest
Feb 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. #ifndef CRYPTOACCOUNT_H
  2. #define CRYPTOACCOUNT_H
  3.  
  4. #include <iostream>
  5. #include <string>
  6. #include <cstdlib>
  7.  
  8. #define RANGE 300
  9.  
  10. using namespace std;
  11.  
  12. extern double currentPrice;
  13.  
  14. typedef struct {
  15. double balance = 0; //US $ amount remaining in your account.
  16. double coins =0; //Number of coins you own. (usually a fraction).
  17. } Account;
  18.  
  19.  
  20. int getUserOptions();
  21. double getInitialDepositFromUser();
  22. void process(); //top level function called by main();
  23. void initialize(Account* account, double deposit);
  24. //deposit is in US dollars
  25. bool buyMore(Account* account, double coins);
  26. bool sellSome(Account* account, double coins);
  27. void print(Account* account);
  28.  
  29.  
  30.  
  31.  
  32.  
  33. #include "cryptoaccount.h"
  34.  
  35.  
  36.  
  37.  
  38. int getUserOptions()
  39. {
  40. string choice();
  41. cout << "Enter an option" << endl << "Deposit" << endl << "buy" << endl << "sell" << "print" << endl;
  42. cin >> choice();
  43. if (choice() == "Deposit")
  44. {
  45. getInitialDepositFromUser();
  46. }
  47. else if(choice() == "buy")
  48. {
  49. buyMore;
  50. }
  51. else if(choice() == "sell")
  52. {
  53. sellSome;
  54. }
  55. else if(choice() == "print")
  56. {
  57. print;
  58. }
  59. else
  60. {
  61. cout << "does not work try one of the options";
  62. }
  63. /** cout what would you like to do?
  64. sin option sell buy check price print account balance
  65. loop it after process is complete if user types N close project**/
  66. }
  67. double getInitialDepositFromUser()
  68. {
  69. double deposit;
  70. cout << "Enter an amount you would like to deposit into the account"<<endl;
  71. cin >> deposit;
  72. return deposit;
  73.  
  74. /**prompt to deposit money into crypto**/
  75. }
  76. void process()
  77. {
  78. getUserOptions();
  79. getInitialDepositFromUser();
  80. initialize(account, deposit);
  81. buyMore(account, coins);
  82. sellSome(account, coins);
  83. print(account);
  84.  
  85. }//top level function called by main();
  86. void initialize(Account* account, double deposit)
  87. {
  88. account.balance == deposit + account.balance;
  89. /** Set account balance to 0? amount they deposited then use this info to buy or sell **/
  90. }
  91. //deposit is in US dollars
  92. bool buyMore(Account* account, double coins)
  93. {
  94. double buyamount;
  95. double cost;
  96.  
  97. cout << "How many coins would you like to buy?" << endl;
  98. cin >> buyamount;
  99. buyamount * currentPrice == cost;
  100. if (account.balance - cost > 0)
  101. {
  102. account.balance - cost = account.balance;
  103. coins + buyamount;
  104. return true;
  105. }
  106. else
  107. {
  108. return false;
  109. }
  110. /** if it returns true the buyer has bought sucessfully no errors*/
  111. }
  112. bool sellSome(Account* account, double coins)
  113. {
  114. double cost;
  115. double amtofcoin;
  116. cout << "How many coins would you like to buy?" <<endl;
  117. cin >> amtofcoin;
  118. if (coins - amtofcoin > 0)
  119. {
  120. amtofcoin * currentPrice == cost;
  121. coins - amtofcoin == coins;
  122. return true;
  123. }
  124. else
  125. {
  126. return false;
  127. }
  128.  
  129.  
  130.  
  131. /** if it returns true the seller has sold sucessfully no errors*/
  132. }
  133. void print(Account* account)
  134. {
  135. double usdcoins;
  136. double total;
  137.  
  138. cout <<"Your account balance is " account.balance << endl;
  139. cout << "You have " account.coins "amount of coins" << endl;
  140. account.coins * currentPrice = usdcoins;
  141. usdcoins + account.balance = total;
  142. cout << total "Is your total amount";
  143.  
  144. /**print balance back to user **/
  145. }
  146.  
  147. #include "cryptoaccount.h"
  148.  
  149. double currentPrice = 1000 + (0.5 - ((double)rand()) / RAND_MAX)*RANGE;
  150.  
  151. int main()
  152. {
  153.  
  154. process();
  155. return 0;
  156. }
Add Comment
Please, Sign In to add comment