Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <limits>
- using namespace std;
- //Global Variables
- //Global string arrays
- string USERNAME[9999] = { "Doodle", "Kinchi", "Multi" }; //starting usernames
- string PASSWORD[9999] = { "54476", "12345", "Airplane" }; // starting passwords
- //Global float balance
- float balance[9999] = {5000, 4000, 3000}; //starting respective balance
- //Global user number (for arrays)
- int userNo;
- int userMemory = 3; //start at fourth term
- //Prototype Variables
- //Account Functions
- bool login(void);
- void registerAccount(void);
- //Action
- float withdraw(void);
- float deposit(void);
- void check(void);
- void cancel(void);
- void exitProgram(void);
- //Tab
- void tab(void);
- void tab2(void);
- void tab3(void);
- main(){
- bool exit = false;
- tab();tab3();
- tab2();cout << "Welcome to Carl's Bank";
- tab();tab3();
- cout << endl;
- while (exit != true){
- string input;
- do {
- tab();tab3();
- tab2();cout << "Carl's Bank: Home Menu";
- tab();tab3();
- cout << endl;
- tab2();
- cout << "[1] Login";
- cout << endl;
- cout << endl;
- tab2();
- cout << "[2] Register";
- cout << endl;
- cout << endl;
- tab2();
- cout << "[3] Exit";
- cout << endl;
- cout << endl;
- cout << endl;
- tab2();
- cout << "Input: ";
- cin >> input;
- } while (!(input == "1" || input == "2" || input == "3"));
- if (input == "1"){
- bool valid = login();
- if (valid){
- tab2();
- cout << "Greetings, " << USERNAME[userNo];
- bool cancel = false;
- while (!(cancel)){
- string input2;
- do {
- cout << endl;
- tab();tab3();
- tab2();
- cout << "Carl's Bank: Action";
- tab();tab3();
- cout << endl;
- tab2();
- cout << "[1] Deposit Money";
- cout << endl;
- cout << endl;
- tab2();
- cout << "[2] Withdraw Money";
- cout << endl;
- cout << endl;
- tab2();
- cout << "[3] Check Balance";
- cout << endl;
- cout << endl;
- tab2();
- cout << "[4] Log out";
- cout << endl;
- cout << endl;
- cout << endl;
- tab2();
- cout << "Input: ";
- cin >> input2;
- } while (!(input2 == "1" || input2 == "2" || input2 == "3" || input2 == "4"));
- if (input2 == "1"){
- balance[userNo] += deposit();
- }
- else if (input2 == "2"){
- balance[userNo] -= withdraw();
- }
- else if (input2 == "3"){
- check();
- }
- else if (input2 == "4"){
- cancel = true;
- }
- }
- }
- }
- else if (input == "2"){
- registerAccount();
- }
- else if (input == "3"){
- exitProgram();
- }
- }
- }
- //login function
- bool login(void){
- string username;
- string password;
- cout << endl;
- cout << endl;
- tab();tab3();
- tab2();
- cout << "Carl's Bank: Login";
- tab();tab3();
- cout << endl;
- tab2();
- cout << "Enter Username: ";
- cin >> username;
- cout << endl;
- tab2();
- cout << "Enter Password: ";
- cin >> password;
- cout << endl;
- for (int i = 0; i < 100; i++){
- if ((username.compare(USERNAME[i]) == 0) &&
- (password.compare(PASSWORD[i]) == 0)){
- userNo = i;
- return true;
- }
- }
- return false;
- }
- float withdraw(void){
- float x;
- bool validInput = false;
- x = -1;
- cout << endl;
- do {
- cout << endl;
- tab2();
- cout << "How much do you want to withdraw? ";
- cin >> x;
- if (!(validInput = cin.good())){
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- } while (!(x >= 0 && x <= balance[userNo]));
- cout << endl;
- tab2();
- cout << setprecision(2) << fixed;
- cout << "Php " << x << " has been reduced from your account . . . ";
- cout << endl;
- system("pause");
- return x;
- }
- float deposit(void){
- float x;
- bool validInput = false;
- cout << endl;
- do {
- cout << endl;
- tab2();
- cout << "How much do you want to deposit? ";
- cin >> x;
- if (!(validInput = cin.good())){
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- } while (!(x >= 0) && !validInput);
- cout << endl;
- tab2();
- cout << setprecision(2) << fixed;
- cout << "Php " << x << " has been added to your account . . . ";
- cout << endl;
- system("pause");
- return x;
- }
- void check(void){
- cout << endl;
- cout << endl;
- tab2();
- cout << setprecision(2) << fixed;
- cout << "Your balance: Php " << balance[userNo];
- cout << endl;
- system("pause");
- }
- void tab(void){
- cout << endl;
- for (int a = 0; a <= 15; a++){
- cout << " ";
- }
- }
- void tab2(void){
- for (int a = 0; a <= 17; a++){
- cout << " ";
- }
- }
- void tab3(void){
- for (int a = 0; a <= 30; a++){
- cout << "=";
- }
- cout << endl;
- }
- void registerAccount(void){
- string input, input2;
- float input3;
- int b = 0, c, d;
- tab();tab3();
- tab2();
- cout << "Carl's Bank: Register";
- tab();tab3();
- cout << endl;
- do {
- d = 0;
- tab2();
- cout << "Enter Username: "; cin >> input;
- cout << endl;
- cout << endl;
- for (c = 0; c <= userMemory-1; c++){
- if (input == USERNAME[c]){
- d = 1;
- }
- if (d == 1){
- b = 0;
- }
- else b = 1;
- }
- if (b == 0){
- tab2();
- cout << "This username has already been used . . . ";
- cout << endl;
- cout << endl;
- system("pause");
- }
- } while(b == 0);
- tab2();
- cout << "Enter Password: "; cin >> input2;
- cout << endl;
- cout << endl;
- bool validInput = false;
- do {
- tab2();
- cout << "Deposit Balance: "; cin >> input3;
- cout << endl;
- if (!(validInput = cin.good())){
- cin.clear();
- cin.ignore(numeric_limits<streamsize>::max(), '\n');
- }
- } while (input3 <= 0 && !validInput);
- USERNAME[userMemory] = input;
- PASSWORD[userMemory] = input2;
- balance[userMemory] = input3;
- userMemory++;
- }
- void exitProgram(void){
- cout << endl;
- cout << endl;
- tab2();
- cout << "Ending program . . . ";
- cout << endl;
- cout << endl;
- abort();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement