void withdrawl(BankAccount account[], int num_accts){
    int accountnum = 0;
    //prompt the user for an account number
    accountnum = accountNumPrompt();
    //validate that account number
    accountnum = find_acct(account, num_accts, accountnum);
    if(accountnum == -1){
        //give error if its not found
        string message = "We couldn't find an account by that number";
        error(message);
        withdrawl(account, num_accts);
    }else{
        //keep asking until you get a valid amount
        BankAccount * b = &account[accountnum];
        while(true){
            double howmuch = 0.00;
            cout << endl << "How much do you want to withdraw?" << endl;
            cin >> howmuch;
            if(b->withdraw(howmuch)){
                cout << endl << howmuch << " has been withdrawn from account: " << b->getAccountNumber() << endl;
                break;
            }else{
                cout << "Acount " << b->getAccountNumber() << " does not have sufficient funds." << endl;
                
            }
        }
    }
}
Esempio n. 2
0
int main ()
{
    BankAccount one{"Fist one", "Three hundre", 300};
    BankAccount two = BankAccount("Second two", "zero");
    BankAccount three = BankAccount();
    one.show();
    one.deposit(500);
    two.show();

    three = BankAccount("one million", "one million", 100000);
    three.show();
    three.withdraw(7852);
    three.show();
    one.show();
    return 0;
}
void mainMenu()
{
    int mainChoice; // choice for top menu
    
	// stockaccount object
	StockAccount stockObj;
	// bankaccount object
	BankAccount bankObj;

	// link two balance
	bankObj.setBalance(stockObj.getBalance());

    do {
        instructionTop();
        cin >> mainChoice;
		while (cin.fail()){
			cout << "\nPlease enter an integer value: ";
			cin.clear();
			cin.ignore();
			cin >> mainChoice;
		}

        switch ( mainChoice ) {
            case 1:
            {
                // stock menu
                cout << "\nStock Portfolio Account" << endl;

				// update balance
				stockObj.setBalance(bankObj.getBalance());

                int stockChoice; // choice for stock menu
                
                string stockSymbol; // stock symbol
                int numberShare; // number of shares
                double maxPrice; // max price to buy shares
                double minPrice; // min Price to sell shares
				string time_start, time_end; // time period to view graph
                
                do {
                    stockInstruction();
                    cin >> stockChoice;

					while (cin.fail()){
						cout << "\nPlease enter an integer value: ";
						cin.clear();
						cin.ignore();
						cin >> stockChoice;
					}

                    //StockAccount *stockPtr = &account;
                    
                    switch ( stockChoice ) {
                        case 1:
                            // display price for stock
                            cout << "\nPlease enter the stock symbol: ";
                            cin >> stockSymbol;
                            stockObj.displayPrice( stockSymbol ); // WORKING ON IT
                            break;
                        case 2:
                            // display current portfolio
                            //cout << "display current portfolio" << endl;
							stockObj.displayPortfolio();
                            break;
                        case 3:
                            // buy shares
                            cout << "Please enter the stock symbol you wish to purchase: ";
                            cin >> stockSymbol;
							
                            cout << "Please enter the number of shares: ";
                            cin >> numberShare;
							while (cin.fail()){
								cout << "\nPlease enter an integer value: ";
								cin.clear();
								cin.ignore();
								cin >> numberShare;
							}

                            cout << "Please enter the maximum amount you are willing to pay per share: $";
                            cin >> maxPrice;
							while (cin.fail()){
								cout << "\nPlease enter a double value: $";
								cin.clear();
								cin.ignore();
								cin >> maxPrice;
							}

							stockObj.buyStock(&Node(stockSymbol, numberShare), maxPrice);
                            
                            break;
                        case 4:
                            // sell shares
                            cout << "Please enter the stock symbol you wish to sell: ";
                            cin >> stockSymbol;
                            cout << "Please enter the number of shares: ";
                            cin >> numberShare;

							while (cin.fail()){
								cout << "\nPlease enter an integer value: ";
								cin.clear();
								cin.ignore();
								cin >> numberShare;
							}

                            cout << "Please enter the minimum amount you are willing to sell per share: $";
                            cin >> minPrice;
							while (cin.fail()){
								cout << "\nPlease enter a double value: $";
								cin.clear();
								cin.ignore();
								cin >> minPrice;
							}

							stockObj.sellStock(&Node(stockSymbol, numberShare), minPrice);
                            
                            break;
                        case 5:
                            // view matlab graph
							cout << "\nPlease select the time period in the graph: " << endl;
							cout << "Start Date (mm/dd/yyyy): ";
							cin >> time_start;
							cout << "\nEnd Date (mm/dd/yyyy): ";
							cin >> time_end;
							stockObj.viewGraph(time_start, time_end);
                            
                            break;
                        case 6:
                            // view transaction history
							stockObj.viewHistory();
                            
                            break;
                        
                    } // end stock switch
                } while ( stockChoice != 7 );
                
                break;
            } // end case 1
            case 2:
            {
                // bank menu
                cout << "\nBank Account" << endl;

				// update balance
				bankObj.setBalance(stockObj.getBalance());

                int bankChoice; // choice for bank menu
                
                double amount; // amount of money to deposit or withdraw
                
                do {
                    bankInstruction();
                    cin >> bankChoice;
                    
					while (cin.fail()){
						cout << "\nPlease enter an integer value: ";
						cin.clear();
						cin.ignore();
						cin >> bankChoice;
					}

                    switch ( bankChoice ) {
                        case 1:
                            // view account balance
                            
							bankObj.viewBalance();
                            break;
                        case 2:
                            // deposit
							
                            cout << "Please select the amount you wish to deposit: $";
                            cin >> amount;
							
							while (cin.fail()){
								cout << "\nPlease enter a double value: $";
								cin.clear();
								cin.ignore();
								cin >> amount;
							}
							
							bankObj.deposit(amount);
                            break;
                        case 3:
                            // withdraw
                            cout << "Please select the amount you wish to withdraw: $";
                            cin >> amount;
                            
							while (cin.fail()){
								cout << "\nPlease enter a double value: $";
								cin.clear();
								cin.ignore();
								cin >> amount;
							}
							bankObj.withdraw(amount);

                            break;
                        case 4:
                            // print history
							bankObj.printHistory();
                            
                            break;
                    } // end bank switch
                } while ( bankChoice != 5 );
                
                break;
            } // end case 2
        } // end main switch
    } while ( mainChoice != 3 );

}