Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ATM MACHINE PROGRAM BY CHRIS BROOKS, TYLER GREENE, & ETHAN WANG SO
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Only works in Cloud9 in a folder with "loginData.txt" & "userBalance.txt"
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- */
- #include <iostream>
- #include <fstream>
- #include <stdlib.h>
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
- #include <iomanip>
- using namespace std;
- string bar = "===========================================\n";
- // function prototypes
- void printIntroMenu();
- void printMainMenu();
- void start();
- bool login();
- void createAccount();
- // global variable (use this variable to store the user’s menu selection)
- string menuInput;
- string username;
- string pass;
- // the main function
- int main() {
- // TO WRITE A WELCOME MESSAGE HERE
- printIntroMenu();
- cin >> menuInput;
- if (menuInput == "l") {
- if (login() == true)
- start();
- else
- return 0;
- }
- else if (menuInput == "c")
- createAccount();
- else if (menuInput == "q")
- return 0;
- return 0;
- }
- void printIntroMenu() {
- cout << "Hi! Welcome to the ATM Machine!\n"
- << "Please select an option from the menu below:\n"
- << "l -> Login\n"
- << "c -> Create New Account\n"
- << "q -> Quit\n";
- }
- void printMainMenu() {
- cout << "d -> Deposit Money\n"
- << "w -> Withdraw Money\n"
- << "x -> Exit\n";
- }
- void start() {
- double balance;
- string currentLine;
- fstream myfile("userBalance.txt");
- for (int lineNum = 0; getline(myfile, currentLine) && lineNum < 5; lineNum++) {
- if (lineNum == 0)
- balance = stod(currentLine);
- }
- cout << fixed << showpoint << setprecision(2);
- cout << bar << "Your current balance is: $" << balance << endl << bar;
- printMainMenu();
- cout << bar;
- cin >> menuInput;
- if (menuInput == "d") {
- // DEPOSIT
- float depositAmt;
- cout << "How much money would you like to deposit?" << endl;
- cin >> depositAmt;
- balance = balance + depositAmt;
- cout << bar << "Your balance is now: $" << balance << endl << bar;
- myfile.close();
- ofstream myfile;
- myfile.open ("userBalance.txt");
- myfile << balance;
- myfile.close();
- }
- else if (menuInput == "w") {
- // WITHDRAW
- float withdrawAmt;
- cout << "How much money would you like to withdraw?" << endl;
- cin >> withdrawAmt;
- if ((balance - withdrawAmt) < 0) {
- cout << "You don't have enough money in your account to make this transaction!" << endl;
- }
- else {
- balance = balance - withdrawAmt;
- }
- cout << bar << "Your balance is now: $" << balance << endl << bar;
- myfile.close();
- ofstream myfile;
- myfile.open ("userBalance.txt");
- myfile << balance;
- myfile.close();
- }
- else if (menuInput == "x")
- cout << "Goodbye." << endl;
- }
- //ifstream infile;
- //infile.open(“loginData.txt”);
- void createAccount() {
- ofstream myfile;
- myfile.open ("loginData.txt");
- cout << "Type in your username: ";
- cin >> username;
- myfile << "user: " << endl << username << endl;
- cout << "Type in your password: ";
- cin >> pass;
- myfile << "pass: " << endl << pass << endl;
- myfile.close();
- myfile.open ("userBalance.txt");
- myfile << 0;
- myfile.close();
- }
- bool login() {
- cout << "Please print user id:\n";
- cin >> username;
- cout << "Please print your password:\n";
- cin >> pass;
- ifstream infile("loginData.txt");
- string currentLine;
- string filedUsername;
- string filedPassword;
- for (int lineno = 0; getline(infile, currentLine) && lineno < 5; lineno++) {
- if (lineno == 1)
- filedUsername = currentLine;
- if (lineno == 3)
- filedPassword = currentLine;
- }
- if (username == filedUsername && pass == filedPassword) {
- cout << endl << "Login successful." << endl;
- return true;
- }
- else {
- cout << endl << "Invalid username/password combination." << endl;
- return false;
- }
- infile.close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement