Here is the first account. I want to add 4 more accounts.
Code:// preprocessor directives #include <cstddef> #include <iostream> #include <fstream> #include <string> #include<stdlib.h> #include<stdio.h> //using namespace standard using namespace std; //void functions void Begin1(); // function that begins account 1 void depositc(); // function that begins account 1's deposit to checking section void withdrawc(); // function that begins account 1's withdraw from checking section void balancec(); // function that begins account 1's balance of checking account section void deposits(); // function that begins account 1's deposits to savings section void withdraws(); // function that begins account 1's withdraw from savings section void balances(); // function that begins account 1's balance of savings account section void transferc(); // function that begins account 1's transfer to checking section void transfers(); // function that begins account 1's transfer to savings section int selection; // variable to store user's response to what transaction they want to complete. int select; // variable to store user's response to which section they want to withdraw from (checking or savings) int select2; // variable to store user's response to which section they want to deposit to (checking or savings) int select3; // variable to store user's response to which section they want to view their balance of (checking or savings) int select4; // variable to store user's response to which section they want to transfer to (checking or savings) int main() // main function { // declare variable constants, strings, and arrays to store the user's account number and pin number const size_t size = 5; string Number[ size ] = { "1234" }; //stores user's account number string PinNumber[ size ] = { "2000" }; // stores user's pin number bool access = false; string Num; //stores user's input for account number string Pin; // stores user's input for pin number do { system("cls"); // clears the screen cout<<endl; // carriage return cout<<endl; cout<<"\\\\\\\\\\\\Welcome to TWC ATM /////////////"<<endl; // outputs "Welcome to TWC ATM" to the screen cout<<endl; cout<<"Enter your Account Number: "; // outputs a statement asking the user to enter their account number cin>>Num; // stores user's input for account number cout<<"\n"<<endl; cout<<"\n"<<endl; cout<<"Enter your PIN Number: "; // outputs a statement asking the user to enter their pin number cin>>Pin; // stores users input for pin number system ("cls"); // clears the screen cout<<"\n"<<endl; for ( size_t i = 0; i < size; i++ ) { if ( ( Num == Number[ i ] ) && ( Pin == PinNumber[ i ] ) ) { access = true; } if (Pin == "2000" && Num == "1234") // if the account number and the pin number match in the previously declared arrays then access is granted. {Begin1(); access = false; break;} } } while ( access == false ); } //////////////////////////////////////////First Account////////////////////////////////////// void Begin1(){ // begins account 1 cout<<"Welcome Kelly Martin."<<endl; // outputs a message welcoming the first user. cout<<endl; cout<<"What would you like to do today?"<<endl; // outputs a message asking the user what transaction they want to do. cout<<"(1)Withdraw"<<endl; cout<<"(2)Deposit"<<endl; cout<<"(3)View Balance"<<endl; cout<<"(4)Transfer funds"<<endl; cout<<"(5)Exit this Account"<<endl<<endl; cout<<"Please choose an option by pressing (1), (2),(3),(4), or (5): "; // asks the user to choose an option 1-5. cin>>selection; // stores the users input to which option they chose. system ("cls"); // clears the screen cout<<"\n"<<endl; switch (selection)// switches the user's response with the corresponding case. { case 1: // begins case 1 cout<<"(3)Withdraw Checking"<<endl; // asks the user which account they want to withdraw from (checking or savings) cout<<"(4)Withdraw Savings"<<endl; cout<<endl; cout<<"Enter your selection: "; // asks the user to enter their selection cin>>select; // stores user's input system ("cls"); // clears the screen switch (select) // switches the user's input with the corresponding case. { case 3: withdrawc(); // if the user chooses case 3; the program calls the withdraw from checking function. break; case 4: withdraws(); // if the user chooses case 4; the program calls the withdraw from savings function. break; default: cin.clear(); // restores input stream; cout<<"You entered invalid number, Please Try again"<<endl; // Tells the user they entered an invalid number. system("pause"); // pauses the screen cin.ignore(); // clears the buffer; system("cls"); // clears the screen; Begin1(); } break; case 2: // begins case 2 cout<<"(3)Deposit Checking"<<endl; // outputs a statement asking the user which account they want to deposit to (checking or savings) cout<<"(4)Deposit Savings"<<endl; cout<<endl; cout<<"Enter your selection: "; // asks the user to enter their selection cin>>select2; // stores the user's input system ("cls"); // clears the screen switch (select2) // switches the user's in put with the corresponding case. { case 3: depositc(); // if the user chooses case 3; the program calls the deposit to checking function break; case 4: deposits(); // if the user chooses case 4; the program calls the deposit to savings function break; default: cin.clear(); // restores input stream; cout<<"You entered invalid number, Please Try again"<<endl; // tells the user they entered an invalid number system("pause"); // pause the screen cin.ignore(); // clears the buffer; system("cls"); // clears the screen Begin1(); } break; case 3: cout<<"(1)Balance Checking"<<endl; // asks the user which account they want to see the balance of (checking or savings) cout<<"(2)Balance Savings"<<endl; cout<<endl; cout<<"Enter your selection: "; // asks the user to enter their selection cin>>select3; // stores the users input system ("cls"); // clears the screen switch (select3) // switches the users input with the corresponding case. { case 1: balancec(); // if the user chooses case 1; the program calls the balance of checking function. break; case 2: balances(); // if the user chooses case 2; the program calls the balance of savings function. break; default: cin.clear(); // restores the input stream cout<<"You entered invalid number, Please Try again"<<endl; // tells the users they entered an invalid number system("pause"); // pauses the screen cin.ignore(); // clears the buffer system("cls"); // clears the screen Begin1(); } break; case 4: cout<<"(1)Transfer from Checking to Savings"<<endl; // asks the user which account they want to transfer to or from (checking to savings or savings to checking) cout<<"(2)Transfer from Savings to Checking"<<endl; cout<<endl; cout<<"Enter your selection: "; // asks the user to enter their selection cin>>select4; // stores the user's input system ("cls"); // clears the screen switch (select4) // switches the users input with the corresponding case. { case 1: transferc(); // if the user chooses case 1; the program calls the transfer to checking function break; case 2: transfers(); // if the user chooses case 2; the program calls the transfer to savings function break; default: cin.clear(); // restores the input stream cout<<"You entered invalid number, Please Try again"<<endl; // tells the user they entered an invalid number system("pause"); // pauses the screen cin.ignore(); // clears the buffer system("cls"); // clears the screen Begin1(); } break; case 5: cout<<endl; cout<<endl; cin.clear(); // restores the input stream cout<<"\t\tThank you Kelly for using TWC ATM. Have a good day!"<<endl; // tells the user thank you and have a good day cout<<endl; cout<<endl; cout<<endl; cout<<endl; system ("pause"); // pauses the screen system ("cls"); // clears the screen cin.clear(); // restores the input stream cin.fail(); // stops the program break; default: cin.clear(); // restores the input stream cout<<"You entered invalid number, Please Try again"<<endl; // tells the user they entered an invalid number system("pause"); // pauses the screen cin.ignore(); // clears the buffer system("cls"); // clears the screen Begin1(); } } ////////////////////////////////////////////////Checking/////////////////////////////////////// void withdrawc(){ // begins the withdraw from checking function float amountw; // variable to store amount user withdraws from checking float bal; // variable to update the checking account balance { cout<<"\n"<<endl; cout<<"How much would you like to withdraw? $"; // asks the user the amount they want to withdraw cin>>amountw; while(cin.fail()) // if the amount they enter is more than the balance of their checking account the program will not continue. { std::cout <<"Please enter a valid amount to withdraw: $"; // tells the user to enter a valid amount to withdraw std::cin.clear(); // restores the input stream std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); // clears the buffer std::cin>>amountw; // stores the users input to the amount they want to withdraw } if(amountw < 0) // if the amount they input to withdraw is a negative number the program multiplies the number by -1 to correct their mistake. amountw = amountw * -1; } { ifstream getinfo("a:\\check.txt"); // opens the checking account text file getinfo>>bal; // gets the balance of the checking account getinfo.close(); // closes the checking account text file bal = bal - amountw; // updates the balance of the checking account file do { if(bal < 0) // if the balance of their checking account is negative the program will not continue { cout<<"You can not withdraw more than your Checking balance of: $"<<(bal + amountw) <<endl; // tells the user they cannot withdraw more than the balance of their checking account cout<<"\n"<<endl; cout<<"How much would you like to withdraw from Checking? $"; cin>>amountw; if(amountw < 0) amountw = amountw * -1; ifstream getinfo("a:\\check.txt"); getinfo>>bal; getinfo.close(); bal = bal - amountw; } }while(bal < 0); cout <<"\n"<<endl; cout<<"*********************************************************************"<<endl; cout<<"\n"<<endl; cout<<"\n"<<endl; ofstream putinfo("a:\\check.txt"); putinfo<<bal << endl; putinfo.close(); } cout<<"\n"<<endl; cout <<"Kelly" <<","<<" you withdrew $"<< amountw <<endl; cout<<"\n"<<endl; cout<<"Your new checking balance is: $"<<bal<<endl; cout<<"\n"<<endl; system ("pause"); system ("cls"); Begin1(); } void depositc(){ float amountd; float bal; { cout<<"\n"<<endl; cout<<"How much would you like to deposit? $"; cin>>amountd; while(cin.fail()) { std::cout <<"Please enter a valid amount to deposit: $"; std::cin.clear(); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); std::cin>>amountd; } if(amountd < 0) amountd = amountd * -1; } { ifstream getinfo("a:\\check.txt"); getinfo>>bal; getinfo.close(); bal = bal + amountd; cout <<"\n"<<endl; cout<<"*********************************************************************"<<endl; cout<<"\n"<<endl; cout<<"\n"<<endl; ofstream putinfo("a:\\check.txt"); putinfo<<bal << endl; putinfo.close(); } cout<<"\n"<<endl; cout << "Kelly"<<","<<" you deposited $"<< amountd <<endl; cout<<"\n"<<endl; cout<<"Your new checking balance is: $"<<bal<<endl; cout<<"\n"<<endl; system ("pause"); system ("cls"); Begin1(); } void balancec(){ float bal; { ifstream getinfo("a:\\check.txt"); getinfo>>bal; getinfo.close(); if (bal < 0) bal = 0; bal = bal; cout <<"\n"<<endl; cout<<"*********************************************************************"<<endl; cout<<"\n"<<endl; cout<<"\n"<<endl; } cout<<"\n"<<endl; cout << "Kelly"<<","<<" your checking balance is $"<< bal <<endl; cout<<"\n"<<endl; cout<<"\n"<<endl; system ("pause"); system ("cls"); Begin1(); } void transferc(){//opens with check.txt file and subtracts from it float amountt; float bal; { cout<<"\n"<<endl; cout<<"How much would you like to transfer from Checking to Savings? $"; cin>>amountt; while(cin.fail()) { std::cout <<"Please enter a valid amount to transfer: $"; std::cin.clear(); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); std::cin>>amountt; } if(amountt < 0) amountt = amountt * -1; } { ifstream getinfo("a:\\check.txt"); getinfo>>bal; getinfo.close(); bal = bal - amountt; do { if(bal < 0) { cout<<"You can not transfer more than your Checking balance of: $"<<(bal + amountt) <<endl; cout<<"\n"<<endl; cout<<"How much would you like to transfer from Checking to Savings? $"; cin>>amountt; if(amountt < 0) amountt = amountt * -1; ifstream getinfo("a:\\check.txt"); getinfo>>bal; getinfo.close(); bal = bal - amountt; } }while(bal < 0); cout <<"\n"<<endl; cout<<"*********************************************************************"<<endl; ofstream putinfo("a:\\check.txt"); putinfo<<bal << endl; putinfo.close(); cout<<"\n"<<endl; cout <<"Kelly" <<","<<" you withdrew from Checking $"<< amountt <<endl; cout<<"\n"<<endl; cout<<"Your new checking balance is: $"<<bal<<endl; } { ifstream getinfo("a:\\sav.txt"); getinfo>>bal; getinfo.close(); bal = bal + amountt; ofstream putinfo("a:\\sav.txt"); putinfo<<bal << endl; putinfo.close(); cout<<"\n"<<endl; cout << "Kelly"<<","<<" you deposited to Savings $"<< amountt <<endl; cout<<"\n"<<endl; cout<<"Your new Savings balance is: $"<<bal<<endl; cout<<"\n"<<endl; cout<< "\n\tPress ENTER key to continue:"<<endl; system ("pause"); system ("cls"); Begin1(); } } ///////////////////////////////Savings///////////////////////////////////////////// void withdraws(){ float amountw; float bal; { cout<<"\n"<<endl; cout<<"How much would you like to withdraw? $"; cin>>amountw; while(cin.fail()) { std::cout <<"Please enter a valid amount to withdraw: $"; std::cin.clear(); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); std::cin>>amountw; } if(amountw < 0) amountw = amountw * -1; } { ifstream getinfo("a:\\sav.txt"); getinfo>>bal; getinfo.close(); bal = bal - amountw; do { if(bal < 0) { cout<<"You can not withdraw more than your Savings balance of: $"<<(bal + amountw) <<endl; cout<<"\n"<<endl; cout<<"How much would you like to withdraw from Savings? $"; cin>>amountw; if(amountw < 0) amountw = amountw * -1; ifstream getinfo("a:\\check.txt"); getinfo>>bal; getinfo.close(); bal = bal - amountw; } }while(bal < 0); cout <<"\n"<<endl; cout<<"*********************************************************************"<<endl; cout<<"\n"<<endl; cout<<"\n"<<endl; ofstream putinfo("a:\\sav.txt"); putinfo<<bal << endl; putinfo.close(); } cout<<"\n"<<endl; cout << "Kelly"<<","<<" you withdrew $"<< amountw <<endl; cout<<"\n"<<endl; cout<<"Your new savings balance is: $"<<bal<<endl; cout<<"\n"<<endl; system ("pause"); system ("cls"); Begin1(); } void deposits(){ float amountd; float bal; { cout<<"\n"<<endl; cout<<"How much would you like to deposit? $"; cin>>amountd; while(cin.fail()) { std::cout <<"Please enter a valid amount to deposit: $"; std::cin.clear(); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); std::cin>>amountd; } if(amountd < 0) amountd = amountd * -1; } { ifstream getinfo("a:\\sav.txt"); getinfo>>bal; getinfo.close(); bal = bal + amountd; cout <<"\n"<<endl; cout<<"*********************************************************************"<<endl; cout<<"\n"<<endl; cout<<"\n"<<endl; ofstream putinfo("a:\\sav.txt"); putinfo<<bal << endl; putinfo.close(); } cout<<"\n"<<endl; cout << "Kelly"<<","<<" you deposited $"<< amountd <<endl; cout<<"\n"<<endl; cout<<"Your new savings balance is: $"<<bal<<endl; cout<<"\n"<<endl; system ("pause"); system ("cls"); Begin1(); } void balances(){ float bal; { ifstream getinfo("a:\\sav.txt"); getinfo>>bal; getinfo.close(); if (bal < 0) bal = 0; bal = bal; cout <<"\n"<<endl; cout<<"*********************************************************************"<<endl; cout<<"\n"<<endl; cout<<"\n"<<endl; } cout<<"\n"<<endl; cout << "Kelly"<<","<<" your savings balance is $"<< bal <<endl; cout<<"\n"<<endl; cout<<"\n"<<endl; system ("pause"); system ("cls"); Begin1(); } void transfers(){//opens with check.txt file and subtracts from it float amountt; float bal; { cout<<"\n"<<endl; cout<<"How much would you like to transfer from Savings to Checking? $"; cin>>amountt; while(cin.fail()) { std::cout <<"Please enter a valid amount to transfer from Savings: $"; std::cin.clear(); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); std::cin>>amountt; } if(amountt < 0) amountt = amountt * -1; } { ifstream getinfo("a:\\sav.txt"); getinfo>>bal; getinfo.close(); bal = bal - amountt; do { if(bal < 0) { cout<<"You can not transfer more than your Savings balance of: $"<<(bal + amountt) <<endl; cout<<"\n"<<endl; cout<<"How much would you like to transfer from Savings to Checking? $"; cin>>amountt; ifstream getinfo("a:\\sav.txt"); getinfo>>bal; getinfo.close(); bal = bal - amountt; } }while(bal < 0); cout <<"\n"<<endl; cout<<"*********************************************************************"<<endl; ofstream putinfo("a:\\sav.txt"); putinfo<<bal << endl; putinfo.close(); } cout<<"\n"<<endl; cout <<"Kelly" <<","<<" you withdrew from Savings $"<< amountt <<endl; cout<<"\n"<<endl; cout<<"Your new Savings balance is: $"<<bal<<endl; ifstream getinfo("a:\\check.txt"); getinfo>>bal; getinfo.close(); bal = bal + amountt; ofstream putinfo("a:\\check.txt"); putinfo<<bal << endl; putinfo.close(); cout<<"\n"<<endl; cout << "Kelly"<<","<<" you deposited to Checking $"<< amountt <<endl; cout<<"\n"<<endl; cout<<"Your new Checking balance is: $"<<bal<<endl; cout<<"\n"<<endl; cout<< "\n\tPress ENTER key to continue:"<<endl; system ("pause"); system ("cls"); Begin1(); }



LinkBack URL
About LinkBacks



