Exemple #1
0
/* The key function for the program. All course of the program is controlled by this function*/
void Bank::OpenForBusiness(Bank our_bank) {
	
	Worker Bob = Worker();
	bool readin = Bob.ReadFromFile(&our_bank); //returns true if items were read in from the file.

	if (readin) {
		cout <<"Welcome back to our bank!" << endl;
	} else {
		cout <<"Wow, a new customer! Welcome to our bank!" << endl;
	}
	restart:
	cout <<"What would you like to do?\n";
	cout <<"	1.Perform a transaction.\n";
	cout <<"	2.Access account records.\n";
	cout <<"	3.Exit.\n";
	
	string choice;
	
	cin >> choice;

	/*PERFORM TRANSACTION*/
	if (choice == "1") {
		bool more_trans = true;

		while (more_trans)	{
			int user_response[2];	//updated in the function via pointers
			Bob.GetTransaction(our_bank, user_response);

			more_trans = Bob.ProcessTransaction(user_response, &our_bank); // returns false if the user is done entering transactions, true otherwise.
		}
		goto restart;
		/*ACCESS ACCOUNT RECORDS*/
	}else if (choice == "2") {
		
		bool more_prints = true;
		while (more_prints)	{
			cout << "Would you like to view an account's transaction history?Y/N\n";
			string resp;
	
			bool badinputchk = true;
	
			while (badinputchk) { //false if we have good input.
			cin >> resp;
				if (resp == "Y") {
					

					string resp2;
					cout << "Which account would you like to view (1,2,3...)? Enter 'all' to view all of them.\n";
					cin.clear();
					cin >> resp2;
				
					tryagain:	//return here if we don't get a valid input

					if (resp2 == "all")	{
						for (int i=1;i<21;i++)	//print all the account transactions					
							PrintAccntInfo(i,our_bank);
							badinputchk = false;
					} else if (atoi(resp2.c_str())) { // if a single account is entered
						int resp_int = stoi(resp2);
						PrintAccntInfo(resp_int,our_bank);
						badinputchk = false;
					
					} else { //if resp is not a valid int
						cout << "Please enter a valid account number (1-20).\n";
						cin.clear();
						cin >> resp2;
						goto tryagain;
					}

				} else if (resp == "N") {
					more_prints = false;
					goto restart;
				} else {
					cin.clear();
					cout << "Please enter either 'Y' or 'N'.\n";
				}
			} //end badinputchk while