Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef CRYPTOACCOUNT_H
- #define CRYPTOACCOUNT_H
- #include <iostream>
- #include <string>
- #include <cstdlib>
- #define RANGE 300
- using namespace std;
- extern double currentPrice;
- typedef struct {
- double balance = 0; //US $ amount remaining in your account.
- double coins =0; //Number of coins you own. (usually a fraction).
- } Account;
- int getUserOptions();
- double getInitialDepositFromUser();
- void process(); //top level function called by main();
- void initialize(Account* account, double deposit);
- //deposit is in US dollars
- bool buyMore(Account* account, double coins);
- bool sellSome(Account* account, double coins);
- void print(Account* account);
- #include "cryptoaccount.h"
- int getUserOptions()
- {
- string choice();
- cout << "Enter an option" << endl << "Deposit" << endl << "buy" << endl << "sell" << "print" << endl;
- cin >> choice();
- if (choice() == "Deposit")
- {
- getInitialDepositFromUser();
- }
- else if(choice() == "buy")
- {
- buyMore;
- }
- else if(choice() == "sell")
- {
- sellSome;
- }
- else if(choice() == "print")
- {
- print;
- }
- else
- {
- cout << "does not work try one of the options";
- }
- /** cout what would you like to do?
- sin option sell buy check price print account balance
- loop it after process is complete if user types N close project**/
- }
- double getInitialDepositFromUser()
- {
- double deposit;
- cout << "Enter an amount you would like to deposit into the account"<<endl;
- cin >> deposit;
- return deposit;
- /**prompt to deposit money into crypto**/
- }
- void process()
- {
- getUserOptions();
- getInitialDepositFromUser();
- initialize(account, deposit);
- buyMore(account, coins);
- sellSome(account, coins);
- print(account);
- }//top level function called by main();
- void initialize(Account* account, double deposit)
- {
- account.balance == deposit + account.balance;
- /** Set account balance to 0? amount they deposited then use this info to buy or sell **/
- }
- //deposit is in US dollars
- bool buyMore(Account* account, double coins)
- {
- double buyamount;
- double cost;
- cout << "How many coins would you like to buy?" << endl;
- cin >> buyamount;
- buyamount * currentPrice == cost;
- if (account.balance - cost > 0)
- {
- account.balance - cost = account.balance;
- coins + buyamount;
- return true;
- }
- else
- {
- return false;
- }
- /** if it returns true the buyer has bought sucessfully no errors*/
- }
- bool sellSome(Account* account, double coins)
- {
- double cost;
- double amtofcoin;
- cout << "How many coins would you like to buy?" <<endl;
- cin >> amtofcoin;
- if (coins - amtofcoin > 0)
- {
- amtofcoin * currentPrice == cost;
- coins - amtofcoin == coins;
- return true;
- }
- else
- {
- return false;
- }
- /** if it returns true the seller has sold sucessfully no errors*/
- }
- void print(Account* account)
- {
- double usdcoins;
- double total;
- cout <<"Your account balance is " account.balance << endl;
- cout << "You have " account.coins "amount of coins" << endl;
- account.coins * currentPrice = usdcoins;
- usdcoins + account.balance = total;
- cout << total "Is your total amount";
- /**print balance back to user **/
- }
- #include "cryptoaccount.h"
- double currentPrice = 1000 + (0.5 - ((double)rand()) / RAND_MAX)*RANGE;
- int main()
- {
- process();
- return 0;
- }
Add Comment
Please, Sign In to add comment