I finished most of the program but having trouble with some

I finished most of the program, but having trouble with some key features. I bolded and italicized the parts I can\'t figure out. I included my code at the bottom. Thanks!

In this assignment you are to create an interactive line command driven C++ program that allows a user to do the following:

Create a bank account by supplying a user id and password

Login using this id and password

Quit the program

Upon successful login, the user will be presented with a menu to do one or more of the following actions:

Withdraw money

Deposit money

Request balance

Quit the program

Ensure that you remove any unnecessary punctuation from monetary input (for example, all $ or other currency symbols should be removed prior to processing, do NOT display an error message to the user for characters which can be removed from the input string without changing the intended value).

Format all monetary outputs on the display Currency (e.g. $ 25,928.43) with all decimal places containing digits.

The User ID and password fields may be any combination of characters which are:

Visible when displayed on the screen (no control characters)

Normally accessible from a standard US keyboard

If login was not successful (for example the id or password did not match) then the user must be returned to the introduction menu.

Items in BOLD are user input:

Welcome to ATM Machine

          Please select an option:

l -> Login

c -> Create New Account

q -> Quit

> l

Please enter your user id: Brittney

Please enter your password: 12345

******** LOGIN FAILED! ********

Please select an option from the menu below:

l -> Login

c -> Create New Account

q -> Quit

> c

Please enter your user name: Brittney

Please enter your password: 12345

Thank You! Your account has been created!

l -> Login

c -> Create New Account

q -> Quit

> l

Please enter your user name: Brittney

Please enter your password: 12345

Access Granted - Brittney

d -> Deposit Money

w -> Withdraw Money

r -> Request Balance

> d

Amount of deposit: $2056.45

d -> Deposit Money

w -> Withdraw Money

r -> Request Balance

> r

Beginning balance : $ 0.00

Deposit amount : $ 2,056.45

Your balance is : $ 2,056.45

d -> Deposit Money

w -> Withdraw Money

r -> Request Balance

> d

Amount of deposit: 56.45

d -> Deposit Money

w -> Withdraw Money

r -> Request Balance

> r

Beginning balance : $ 2,056.45

Deposit amount : $ 56.45

Your balance is $ 2,112.90

d -> Deposit Money

w -> Withdraw Money

r -> Request Balance

> w

Amount of withdrawal: -2.5

d -> Deposit Money

w -> Withdraw Money

r -> Request Balance

> r

Beginning balance : $ 2,112.90

Withdrawal amount : $( 2.50)

Your balance is $ 2,115.40

d -> Deposit Money

w -> Withdraw Money

r -> Request Balance

> w

Amount of withdrawal: 125.57

d -> Deposit Money

w -> Withdraw Money

r -> Request Balance

> r

Beginning balance : $ 2,115.40

Withdrawal amount : $ 125.57

Your balance is $ 1,989.83

d -> Deposit Money

w -> Withdraw Money

r -> Request Balance

> q

Thanks for banking with us!

#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

void CreateAccount(string userName, string userPassword){
   ofstream outAccount;   
   outAccount.open(\"bankAccounts.txt\");
   outAccount << userName << endl;
   outAccount << userPassword << endl;
   outAccount.close();
   return;
}

bool Login(string userName, string userPassword){
   ifstream inAcount;
   inAccount.open(\"bankAccounts.txt\");
  
   string name;
   string password;
  
   if (inAccount.is_open())
   {
       while (inAccount >> name)
       {
           inAccount >> password;
           if (userName == name && userPassword == password){
return true;
           }
       }
   }
inAccount.close();

return false;
}

void Deposit(double &balance, double val){
   balance += val;
   return;
}

void Withdraw(double &balance, double val){
   if (balance >= val)
   {
       balance -= val;
   }
   else{
       cout << \"Withdrawal amount exceeds account balance. Can\'t withdraw!\" << endl;
       cout << endl;
   }
   return;
}

void DisplayBalance(double balance){
   cout << \"Your balance is: $\" << balance << endl;
  
   return;
}

void BankingMenu(){
   double balance = 0.0;
   double depositVal;
   double withdrawalVal;
   char userOption;
  
   while (true)
   {
       cout << \"d -> Deposit Money\" << endl;
       cout << \"w -> Withdraw Money\" << endl;
       cout << \"r -> Request Balance\" << endl;
       cout << \"q -> Quit\" << endl;
       cout << endl;
      
       cin >> userOption;
       cout << endl;
      
       switch (userOption){
           case \'d\':
           case \'D\':
               cout << \"Amount of deposit: \";
               cin >> depositVal;
               Deposit(balance, depositVal);
               break;
      
           case \'w\':
           case \'W\':
               cout << \"Amount of withdrawal: \";
               cin >> withdrawalVal;
               Withdraw(balance, withdrawalVal);
               break;
          
           case \'r\':
           case \'R\':
               cout << \"Beginning balance: $\" << balance << endl;
               DisplayBalance(balance);
               break;
          
           case \'q\':
           case \'Q\':
               //cout << \"Thanks for banking with us!\" << endl;
               exit(1);
               break;
          
           default:
               cout << \"Invalid option. Pick again.\" << endl;
               break;
       }
       cout << endl;
   }
   return;
}

int main() {
   string userName;
   string userPassword;
   char userOption;
  
   cout << \"Welcome to ATM Machine\" << endl;
   cout << endl;

   while (true){
       cout << \"Please select an option:\" << endl;
       cout << endl;
      
       cout << \"l -> Login\" << endl;
       cout << \"c -> Create New Account\" << endl;
       cout << \"q -> Quit\" << endl;
       cout << endl;
      
       cin >> userOption;
       cout << endl;
      
       switch (userOption){
           case \'l\':
           case \'L\':
               cout << \"Please enter your user id: \";
               cin >> userName;
               cout << \"Please enter your password: \";
               cin >> userPassword;
              
               if (Login(userName, userPassword)){
                   cout << endl;
                   cout << \"Access Granted - \" << userName << endl;
                   cout << endl;
                   BankingMenu();
               }
               else{
                   cout << endl;
                   cout << \"******** LOGIN FAILED! ********\" << endl;
               }
               break;
      
           case \'c\':
           case \'C\':
               cout << \"Please enter your user name: \";
               cin >> userName;
               cout << \"Please enter your password: \";
               cin >> userPassword;
               CreateAccount(userName, userPassword);
              
               cout << endl;
               cout << \"Thank You! Your account has been created!\" << endl;
               break;

           case \'q\':
           case \'Q\':
               cout << \"Thanks for banking with us!\" << endl;
               exit(1);
               break;
          
           default:
               cout << \"Invalid option. Pick again.\" << endl;
       }
       cout << endl;
   }
  
   return 0;
}

Welcome to ATM Machine

          Please select an option:

l -> Login

c -> Create New Account

q -> Quit

> l

Please enter your user id: Brittney

Please enter your password: 12345

******** LOGIN FAILED! ********

Please select an option from the menu below:

l -> Login

c -> Create New Account

q -> Quit

> c

Please enter your user name: Brittney

Please enter your password: 12345

Thank You! Your account has been created!

l -> Login

c -> Create New Account

q -> Quit

> l

Please enter your user name: Brittney

Please enter your password: 12345

Access Granted - Brittney

d -> Deposit Money

w -> Withdraw Money

r -> Request Balance

> d

Amount of deposit: $2056.45

d -> Deposit Money

w -> Withdraw Money

r -> Request Balance

> r

Beginning balance : $ 0.00

Deposit amount : $ 2,056.45

Your balance is : $ 2,056.45

d -> Deposit Money

w -> Withdraw Money

r -> Request Balance

> d

Amount of deposit: 56.45

d -> Deposit Money

w -> Withdraw Money

r -> Request Balance

> r

Beginning balance : $ 2,056.45

Deposit amount : $ 56.45

Your balance is $ 2,112.90

d -> Deposit Money

w -> Withdraw Money

r -> Request Balance

> w

Amount of withdrawal: -2.5

d -> Deposit Money

w -> Withdraw Money

r -> Request Balance

> r

Beginning balance : $ 2,112.90

Withdrawal amount : $( 2.50)

Your balance is $ 2,115.40

d -> Deposit Money

w -> Withdraw Money

r -> Request Balance

> w

Amount of withdrawal: 125.57

d -> Deposit Money

w -> Withdraw Money

r -> Request Balance

> r

Beginning balance : $ 2,115.40

Withdrawal amount : $ 125.57

Your balance is $ 1,989.83

d -> Deposit Money

w -> Withdraw Money

r -> Request Balance

> q

Thanks for banking with us!

#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;

void CreateAccount(string userName, string userPassword){
   ofstream outAccount;   
   outAccount.open(\"bankAccounts.txt\");
   outAccount << userName << endl;
   outAccount << userPassword << endl;
   outAccount.close();
   return;
}

bool Login(string userName, string userPassword){
   ifstream inAcount;
   inAccount.open(\"bankAccounts.txt\");
  
   string name;
   string password;
  
   if (inAccount.is_open())
   {
       while (inAccount >> name)
       {
           inAccount >> password;
           if (userName == name && userPassword == password){
return true;
           }
       }
   }
inAccount.close();

return false;
}

void Deposit(double &balance, double val){
   balance += val;
   return;
}

void Withdraw(double &balance, double val){
   if (balance >= val)
   {
       balance -= val;
   }
   else{
       cout << \"Withdrawal amount exceeds account balance. Can\'t withdraw!\" << endl;
       cout << endl;
   }
   return;
}

void DisplayBalance(double balance){
   cout << \"Your balance is: $\" << balance << endl;
  
   return;
}

void BankingMenu(){
   double balance = 0.0;
   double depositVal;
   double withdrawalVal;
   char userOption;
  
   while (true)
   {
       cout << \"d -> Deposit Money\" << endl;
       cout << \"w -> Withdraw Money\" << endl;
       cout << \"r -> Request Balance\" << endl;
       cout << \"q -> Quit\" << endl;
       cout << endl;
      
       cin >> userOption;
       cout << endl;
      
       switch (userOption){
           case \'d\':
           case \'D\':
               cout << \"Amount of deposit: \";
               cin >> depositVal;
               Deposit(balance, depositVal);
               break;
      
           case \'w\':
           case \'W\':
               cout << \"Amount of withdrawal: \";
               cin >> withdrawalVal;
               Withdraw(balance, withdrawalVal);
               break;
          
           case \'r\':
           case \'R\':
               cout << \"Beginning balance: $\" << balance << endl;
               DisplayBalance(balance);
               break;
          
           case \'q\':
           case \'Q\':
               //cout << \"Thanks for banking with us!\" << endl;
               exit(1);
               break;
          
           default:
               cout << \"Invalid option. Pick again.\" << endl;
               break;
       }
       cout << endl;
   }
   return;
}

int main() {
   string userName;
   string userPassword;
   char userOption;
  
   cout << \"Welcome to ATM Machine\" << endl;
   cout << endl;

   while (true){
       cout << \"Please select an option:\" << endl;
       cout << endl;
      
       cout << \"l -> Login\" << endl;
       cout << \"c -> Create New Account\" << endl;
       cout << \"q -> Quit\" << endl;
       cout << endl;
      
       cin >> userOption;
       cout << endl;
      
       switch (userOption){
           case \'l\':
           case \'L\':
               cout << \"Please enter your user id: \";
               cin >> userName;
               cout << \"Please enter your password: \";
               cin >> userPassword;
              
               if (Login(userName, userPassword)){
                   cout << endl;
                   cout << \"Access Granted - \" << userName << endl;
                   cout << endl;
                   BankingMenu();
               }
               else{
                   cout << endl;
                   cout << \"******** LOGIN FAILED! ********\" << endl;
               }
               break;
      
           case \'c\':
           case \'C\':
               cout << \"Please enter your user name: \";
               cin >> userName;
               cout << \"Please enter your password: \";
               cin >> userPassword;
               CreateAccount(userName, userPassword);
              
               cout << endl;
               cout << \"Thank You! Your account has been created!\" << endl;
               break;

           case \'q\':
           case \'Q\':
               cout << \"Thanks for banking with us!\" << endl;
               exit(1);
               break;
          
           default:
               cout << \"Invalid option. Pick again.\" << endl;
       }
       cout << endl;
   }
  
   return 0;
}

Solution

Hi please reas all the commented line

============================================================

code

======================

#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <algorithm>
#include<stdlib.h> //added this lib for atof function, it coverts char array to doubl value
#include <iomanip>
using namespace std;
using namespace std;
#define DOT \'.\' //declaring for display using comma and all
#define COMMA \',\'
#define MAX 50

static char commas[MAX]; // as we need to display the money value with comma we need this

char tmp[MAX];
void CreateAccount(string userName, string userPassword){
ofstream outAccount;
outAccount.open(\"bankAccounts.txt\");
outAccount << userName << endl;
outAccount << userPassword << endl;
outAccount.close();
return;
}
bool Login(string userName, string userPassword){
ifstream inAccount; //here u declare the variable as inAccount but u used as inAcount.open(bankAccounts.txt)
inAccount.open(\"bankAccounts.txt\");

string name;
string password;

if (inAccount.is_open())
{
while (inAccount >> name)
{
inAccount >> password;
if (userName == name && userPassword == password){
return true;
}
}
}
inAccount.close();

return false;
}
void Deposit(double &balance, double val){
balance += val;
return;
}
void Withdraw(double &balance, double val){
if (balance >= val)
{
balance -= val;
}
else{
cout << \"Withdrawal amount exceeds account balance. Can\'t withdraw!\" << endl;
cout << endl;
}
return;
}
void DisplayBalance(double balance){

char tmp[MAX];
sprintf(tmp, \"%.2f\", balance);
// use to copy the content of balance to the array
char *dot = strchr(tmp, DOT); //use to copy the string after first occurence of .(including)

char *src,*dst; // source, dest

if (dot) { // Yes
dst = commas+MAX-strlen(dot)-1;

strcpy(dst, dot);

*dot = 0;
src = --dot;
dst--;
}
else { // No
src = tmp+strlen(tmp)-1;
dst = commas+MAX-1;
}

int len = strlen(tmp);
int cnt = 0;

do {
if ( *src<=\'9\' && *src>=\'0\' ) { // add comma is we added 3 digits already
if (cnt && !(cnt % 3)) *dst-- = COMMA;
cnt++; // digit count increment
}
*dst-- = *src--;
} while (--len);

cout <<\"Your balance is: $\" << dst +1 << endl;

return;
}
void BankingMenu(){
double balance = 0.0;
double depositVal;
double withdrawalVal;
char userOption;
char temp[50]; //added this variable for user input as you need $55 or -56 kind of input (double variable can\'t understand $, -)
int length;
double previous_balance;//for displaying the beginning balance before deposit or withdrawiing
while (true)
{
cout << \"d -> Deposit Money\" << endl;
cout << \"w -> Withdraw Money\" << endl;
cout << \"r -> Request Balance\" << endl;
cout << \"q -> Quit\" << endl;
cout << endl;

cin >> userOption;
cout << endl;

switch (userOption){
case \'d\':
case \'D\':
cout << \"Amount of deposit: \";
cin>>temp; //take user input as char array(string)

length =strlen(temp);//this function is used to get length of string
if(temp[0]==\'$\') //here it will check first char of user input $ or not
{
for(int k=0;k<length;k++) //here it will delete the $symbol from user input , u can add other symbol also
temp[k]=temp[k+1];
}


depositVal=atof(temp);//this atof function convert string to double value
previous_balance=balance;//this variable stores the begining balance for display
Deposit(balance, depositVal);
break;

case \'w\':
case \'W\':
cout << \"Amount of withdrawal: \";//same as d option, refer that
cin>>temp;

length =strlen(temp);
if(temp[0]==\'$\'||temp[0]==\'-\')
{
for(int k=0;k<length;k++)
temp[k]=temp[k+1];
}


withdrawalVal=atof(temp);
previous_balance=balance;

Withdraw(balance, withdrawalVal);
break;

case \'r\':
case \'R\':
if(previous_balance ==0)
cout << \"Beginning balance: $0.00\" << endl;
else
cout <<\"Beginning balance: $\" << previous_balance << endl;
DisplayBalance(balance);
break;

case \'q\':
case \'Q\':
//cout << \"Thanks for banking with us!\" << endl;
exit(1);
break;

default:
cout << \"Invalid option. Pick again.\" << endl;
break;
}
cout << endl;
}
return;
}
int main() {
string userName;
string userPassword;
char userOption;

cout << \"Welcome to ATM Machine\" << endl;
cout << endl;
while (true){
cout << \"Please select an option:\" << endl;
cout << endl;

cout << \"l -> Login\" << endl;
cout << \"c -> Create New Account\" << endl;
cout << \"q -> Quit\" << endl;
cout << endl;

cin >> userOption;
cout << endl;

switch (userOption){
case \'l\':
case \'L\':
cout << \"Please enter your user id: \";
cin >> userName;
cout << \"Please enter your password: \";
cin >> userPassword;

if (Login(userName, userPassword)){
cout << endl;
cout << \"Access Granted - \" << userName << endl;
cout << endl;
BankingMenu();
}
else{
cout << endl;
cout << \"******** LOGIN FAILED! ********\" << endl;
}
break;

case \'c\':
case \'C\':
cout << \"Please enter your user name: \";
cin >> userName;
cout << \"Please enter your password: \";
cin >> userPassword;
CreateAccount(userName, userPassword);

cout << endl;
cout << \"Thank You! Your account has been created!\" << endl;
break;

case \'q\':
case \'Q\':
cout << \"Thanks for banking with us!\" << endl;
exit(1);
break;

default:
cout << \"Invalid option. Pick again.\" << endl;
}
cout << endl;
}

return 0;
}

======================

Thanks

I finished most of the program, but having trouble with some key features. I bolded and italicized the parts I can\'t figure out. I included my code at the bott
I finished most of the program, but having trouble with some key features. I bolded and italicized the parts I can\'t figure out. I included my code at the bott
I finished most of the program, but having trouble with some key features. I bolded and italicized the parts I can\'t figure out. I included my code at the bott
I finished most of the program, but having trouble with some key features. I bolded and italicized the parts I can\'t figure out. I included my code at the bott
I finished most of the program, but having trouble with some key features. I bolded and italicized the parts I can\'t figure out. I included my code at the bott
I finished most of the program, but having trouble with some key features. I bolded and italicized the parts I can\'t figure out. I included my code at the bott
I finished most of the program, but having trouble with some key features. I bolded and italicized the parts I can\'t figure out. I included my code at the bott
I finished most of the program, but having trouble with some key features. I bolded and italicized the parts I can\'t figure out. I included my code at the bott
I finished most of the program, but having trouble with some key features. I bolded and italicized the parts I can\'t figure out. I included my code at the bott
I finished most of the program, but having trouble with some key features. I bolded and italicized the parts I can\'t figure out. I included my code at the bott
I finished most of the program, but having trouble with some key features. I bolded and italicized the parts I can\'t figure out. I included my code at the bott
I finished most of the program, but having trouble with some key features. I bolded and italicized the parts I can\'t figure out. I included my code at the bott
I finished most of the program, but having trouble with some key features. I bolded and italicized the parts I can\'t figure out. I included my code at the bott
I finished most of the program, but having trouble with some key features. I bolded and italicized the parts I can\'t figure out. I included my code at the bott
I finished most of the program, but having trouble with some key features. I bolded and italicized the parts I can\'t figure out. I included my code at the bott

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site