v2.0 of my program?

This is a discussion on v2.0 of my program? within the C++ Programming forums, part of the General Programming Boards category; OK. i originally saw a bank teller program on this site, but i never really looked at the code. I ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    9

    v2.0 of my program?

    OK. i originally saw a bank teller program on this site, but i never really looked at the code. I jsut pasted the code into my compiler, so what you see is all the things that I have gained from tutorial. None of this is copied.

    I need help. What I am trying to do:
    When you get to the menu for the options to withdraw, deposit etc etc, inside the switch/case, i need to find a way so that when the user is done with say, depositing his "cash", i want him to be able to select from the original list of options. HOw would i do this?

    O, and evaluations would be nice. Remember that i am a noob in C++ lol. been doin it for a few days. this is merely practice with if then statements, some loops, and switches.
    THANKs!

  2. #2
    Registered User
    Join Date
    Feb 2008
    Posts
    9
    Code:
     #include <iostream>
    using namespace std;
    main(){
         int a = 256781; //password
         int h = 24781; //pin number
         int current; //current password
         int newcurrent;//new current password
         int newcurrenta;//confirmation password
         int deposit; //amount to be deposited
         int balance = 7000; //current balance
         int withdrawa; //withdrawal amount
         int withdraw; //withdrawl amount for a second transaction
         cout<<"Welcome to the Bank of America.\n";
         cout<<"Please enter your 6-digit password to access your account\n";
         cin>>a;
         cin.ignore();
         for ( a == 256781; a != 256781; ){
               cout<<"Incorrect Password. Please try again.\n";
              cin>>a;
                       }
         if (a=256781){
                      cout<<"You have correctly entered your password\n";
                      cout<<"Please type in your 4-digit pin to continue:\n";
                      cin>>h;
                      cin.ignore();
                      cout<<"\n";
                      cout<<"\n";
                                   for ( h == 24781; h != 24781; ){
                                         cout<<"You have entered an incorrect pin. Please try again\n";
                                         cin>>h;
                                             }
                                   if (h == 24781){
                                        
                                    
                                   
                                               cout<<"Welcome to your writers account\n";
                                               cout<<"What would you like to do?\n";
                                               cout<<"\n";
                                               cout<<"1 Change your password\n";
                                               cout<<"2 Make Deposit\n";
                                               cout<<"3 Withdraw\n";
                                               cout<<"4 Balance\n";
                                                   int option; //option list
                                                   cin>>option;
                                                   cin.ignore();
                                                  switch ( option ) {
                                                        case 1:
                                                               cout<<"Enter your current password\n";
                                                               cin>>a; 
                                                               cin.ignore();
                                                               for ( a == 256781; a != 256781;){
                                                                   cout<<"The password you entered is incorrect\n";
                                                                   cout<<"Please try again\n";
                                                                   cin>>a;
                                                                   cin.ignore();
                                                                   }
                                                               if (a == 256781){
                                                                   cout<<"Please enter a new password\n";
                                                                   cin>>newcurrent;
                                                                   cin.ignore();
                                                                   cout<<"Please enter your password again\n";
                                                                   cin>>newcurrenta;
                                                                   cin.ignore();
                                                                                for ( newcurrent ==newcurrenta; newcurrent != newcurrenta; ){
                                                                                      cout<<"The password you entered was incorrect.\n";
                                                                                      cout<<"Please try again\n";
                                                                                      cin>>newcurrenta;
                                                                                      }
                                                                                if (newcurrent==newcurrenta){
                                                                                      cout<<"Congratulations. Your password has been changed\n";
                                                                                      cout<<"would you like to do anything else?";
                                                                                                              }             
                                                               
                                                               
      
                                                                   break;
                                                         case 2:
                                                               cout<<"How much would you like to deposit?\n";
                                                               cin>>deposit;
                                                               cin.ignore();
                                                               cout<<"Thank you. Your new current balance is\n";
                                                               cout<<(deposit + balance)<<"\n";
                                                               break;
                                                         case 3:
                                                                cout<<"How much would you like to withdraw?\n";
                                                                cin>>withdrawa;
                                                                cin.ignore();
                                                                             while (withdrawa > 5000){
                                                                                   cout<<"ERROR- You may not withdraw more than 5000 USD in one day\n";
                                                                                   cout<<"Please enter another value\n";
                                                                                   cout<<"If you wish to make a transaction greater than 5000 USD\n";
                                                                                   cout<<"Please see one of our bank tellers\n";
                                                                                   cin>>withdraw;
                                                                                   cin.ignore();
                                                                                   }
                                                                                                 if ( withdrawa < 5000 ){
                                                                                                     cout<<"Processing. Your balance is now"<<(balance - withdrawa)<<"\n";
                                                                                                     cout<<"If you wish to make a transaction greater than 5000 USD\n";
                                                                                                     cout<<"Please see one of our Bank tellers\n";
                                                                                                     cout<<"Make another transaction?\n";
                                                                                                     cout<<"[1] yes\n";
                                                                                                     cout<<"[2] no\n";
                                                                                                     int yes; //yes option confirm
                                                                                                     
                                                                                                     switch ( yes ) {
                                                                                                           case 1:
                                                                                                                 cout<<"How much do you want to withdraw?\n";
                                                                                                                 cin>>withdraw;
                                                                                                                 cin.ignore();
                                                                                                                 while ( withdraw > balance-withdrawa-withdraw){
                                                                                                                       cout<<"ERROR- You may not withdraw more than 5000 USD in one day.\n";
                                                                                                                       cout<<"You have already withdrawn"<< withdrawa<<"\n";
                                                                                                                       cout<<"For transactions greater than $5000, see a bank teller\n";
                                                                                                                       cout<<"Enter another withdrawl amount\n";
                                                                                                                       cin>>withdraw;
                                                                                                                       cin.ignore();
                                                                                                                       }
                                                                                                                  if ( withdraw <= 5000-withdrawa-withdraw) {     
                                                                                                                       cout<<"Thank you for using Bank of America\n";
                                                                                                                       cout<<"Your transaction has been processed\n";
                                                                                                                }
                                                                                                                 break;
                                                                                                             case 2:
                                                                                                                    cout<<"Thank you for using Bank of America\n";
                                                                                                                    cout<<"Please come back again\n";
                                                                                                                    break;    
                                                                                                            }
                                                                                                            
                                                                                                     }           
                                                                                   }
                                                                              if (withdrawa <=5000){
                                                                                    cout<<"Processing. Your balance is now"<<balance<<"\n";            
                                                                                    }
                                                                
                                                                 break;
                                                         case 4:
                                                                  cout<<"Your current balance is:"<< balance<<"\n";
                                                                  break;
    
                                                                
                                                                }
                                                                }
                                                                }
                                                                
                                                           
                      cin.get();
                      }

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    26
    For one, I am also new to C++. And to fix your problem put a do while loop just above the

    Code:
    do{
        cout<<"Welcome to your writers account\n";
    and put the while at the very bottom before cinget and make it

    [/CODE]
    } while ( option != 5 )
    cin.get
    [/CODE]


    and then make an option in the option list which says quit and is 5 so that way when they input 5 it will quit.

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    9
    tyvvvm!

  5. #5
    Registered User NeonBlack's Avatar
    Join Date
    Nov 2007
    Posts
    435
    Damn, I should have bought that wide screen monitor for Christmas.

    Code:
         for ( a == 256781; a != 256781; ){
               cout<<"Incorrect Password. Please try again.\n";
              cin>>a;
                       }
         if (a=256781){
    I realize that you are new to C, but I have no clue where you got the idea to use a for loop like that. Also notice right after the for loop in the if statement that you are assigning some number to a, not comparing them. This will usually give you an 'unintended assignment' warning on most compilers.

    I also suggest that you try to break this program into chunks to make it more manageable.
    I copied it from the last program in which I passed a parameter, which would have been pre-1989 I guess. - esbo

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,536
    Inconsistent bracket placement makes the code hard to read. Have a read.
    You're probably using way too much spaces to indent. You can lessen it 4 or so.
    Split code into other functions to make it a little more readable.
    Then it should be way easier to spot silly problems.

    You are unneedlessly indenting where you don't need to and you also use for loops where inappropriate.
    You need to go back to your books a little methinks. Comparison is not for. You also do several unnecessary comparisons for the same thing.
    You even try to input some data in some places that makes no sense.

    Oh and main returns int.
    Last edited by Elysia; 02-12-2008 at 12:09 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #7
    Registered User
    Join Date
    Feb 2008
    Posts
    9
    ahhhhhhhhhhhhhhh!!!!!!!!!!!!!!!!!!!!!
    lol ive only been at it in practice about a couple days so yeah ill work on it. Need to work on which loops to use etc. etc. Anyway thanks for the "constructive criticism?"
    O and the indentations are just cause i hit tab and started typing lol. I needed to distinguish which parts were to go where. lol even if you cant tell i know where everything goes lol. at least more than someone who didnt write it.! have great day all!
    Last edited by mustanghaven; 02-12-2008 at 10:06 PM. Reason: omitted something

  8. #8
    Registered User
    Join Date
    Feb 2008
    Posts
    9
    Quote Originally Posted by NeonBlack View Post
    Damn, I should have bought that wide screen monitor for Christmas.

    Code:
         for ( a == 256781; a != 256781; ){
               cout<<"Incorrect Password. Please try again.\n";
              cin>>a;
                       }
         if (a=256781){
    I realize that you are new to C, but I have no clue where you got the idea to use a for loop like that. Also notice right after the for loop in the if statement that you are assigning some number to a, not comparing them. This will usually give you an 'unintended assignment' warning on most compilers.

    I also suggest that you try to break this program into chunks to make it more manageable.
    should i have used the "while" loop? Im confused just a little. jsut wanna know. I think its the while loop that should have been there?

  9. #9
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    You should use do/while loop here
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  10. #10
    Registered User
    Join Date
    Feb 2008
    Posts
    9
    ty. btw. . .it worked on my comp. The part where you say it should give me a warning. If i enter an incorrect password, then it does what the "for" loop says. If i enter the correct one it continues without problems.

    so anyway thanks for criticism guys
    its wrid tho. casue i jsutt tried using the "while loop" and it does not work

  11. #11
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,536
    That's because you aren't doing it right. In an application that asks for password, it should be something like this, right?

    Code:
    Ask for password
    If password is right, then continue.
    Else if password is wrong,
    	if the user entered wrong password too many times,
    		print error and quit.
    	else,
    		increment wrong password counter.
    Do it all over again.
    Try to implement that logic into your program.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 12:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21