Sign in to follow this  
glyvin

C++ bank program

Recommended Posts

Hi Here is my current working code, im pretty happy with it, I would just like to clean it up and make a few chanes
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
      string name;
      int exit = 8;
      int funds;
      int oneortwo;
      int deposit;
      int currentbalance = 100;
      int withdrawl;
      int wagain;
      cout<< "Hello please enter your name to get to your bank information...\n";
      cin >> name ;
      start:
      cout << "Thank you "<< name<< " you have " <<currentbalance<<"$ in your bank, would you like to Deposit(1)\n or Withdrawl(2) funds?" <<endl;
      cout << "Please select 1 or 2.\n" ;
      cin  >> oneortwo;
      if (oneortwo == 1)
    {
      do
{
      int dagain;
      cout << "You have choosen Deposit, how much would you like to deposit? \n" ;
      cin >> deposit;
      currentbalance = currentbalance + deposit;
      cout << "Your balance is now $" <<currentbalance << endl;
      cout << "Press 1 to make another depsoit or press 9 to quit. "<<"\n";
      cin >>dagain;
      if (dagain == 9)
      exit = exit +1;
      else
       exit = exit;
      } while (exit < 9);
}
      else
      if (oneortwo ==2);
      do
      {
      cout << "You have choosen Withdrawl, how much would you like to withdrawl?\n";
      cin >>withdrawl;
         currentbalance = currentbalance - withdrawl;
      if( currentbalance <=0 )
      {
        currentbalance = currentbalance + withdrawl;
        cout <<"You do not have enough money to make this withdrawl, your current balance is "<<currentbalance<<"\n";
        goto start;
        }

      cout << "Your balance is now $" <<currentbalance <<endl;
      cout <<" Press 1 to make another withdrawl or press 9 to quit. "<<"\n";
      cin >> wagain;
      if (wagain == 9)
      exit = exit +1;
      else 
      exit = exit;
      }while (exit < 9);

      return 0;
}


I am thinking of trying to use some functions to clean this up, might make it a little nicer also looking for a way if the user presses 9 any time during the app to shut the program down trying to work at making my menu work smoother.

Share this post


Link to post
Share on other sites
You have

...
else
exit = exit;
...

two places in your code.
If im not very wrong you can remove both without realy changing anything.
It doesnt matter if the program enters this else or not since it doesnt do anything.

You also have

else if (oneortwo ==2);

Are you sure you want to have that semi-colon at the end?
It will end the if immidiately, so whatever comes after this line is not part of the if

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this