Thread: I need help or clues on how to build an array in C++?

  1. #1
    Registered User
    Join Date
    Dec 2009
    Location
    Huintsville, AL.
    Posts
    14

    I need help or clues on how to build an array in C++?

    This program was design to simulate an ATM machine and so far it works.
    I realize i need other aspects in this program to be more life like
    for EX. I need to build an array that when I punch in a pin number the persons name assigned to that pin will pop up with the available balance already stored inside the array and what ever the withdraw amount it will subtract from that balance and what ever deposit amount it will add to that balance.

    I've added to the original simplified version of the program but I'm stuck on the Arrays.

    Does any body have any clues????

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    
    
    int main()
    {
    
    float Available_Balance [15];
    string NAME [21];
    int DebitCardPin[4];
    double Balance = 0;
    double Withdraw_Amount = 0;
    double Deposit_Amount = 0;
    int  Balance, Withdraw, Deposit;	
    int Option;
    
    char Cancel;
    
    Balance = 1;
    Withdraw = 2;
    Deposit = 3;
    Cancel = 4;
    
    Option = 1,2,3, 4;
    
     
       do 
       {
    cout<<"Please enter your Pin Number :\n";cin>>DebitCardPin; 
    
    
    cout<<"Please choose an option :\n"<<endl;
    
    cout<<"Enter: (1)-Balance, (2)-Withdraw, (3)-Cancel : \n"; cin>> Option;
    
    
    
    
    	if (Option == 1)
    	{
    		cout<<"Your Available Balance Is: \n";
    		cout<<Available_Balance;
    	
    		if (Option == 2)
    	       {
    			cout<<"Please enter amount:\n"<<endl;
    			cin>>Withdraw_Amount;
    			cout<<"please wait while we process you Transaction"<<endl;
    		
    		if (Option == 3)
    		      {
    				 cout<<"Transaction cancled"<<endl;
    				 cout<<"\nHave a nice day";
                           }           
    		 }
               }
        }while (Option!=Cancel);
    	
    
    		return 0;
    }
    Last edited by jason007thomas; 11-21-2011 at 03:21 PM.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Since you're using C++, you could easily use a map.
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675

  4. #4
    Registered User
    Join Date
    Oct 2011
    Posts
    15
    This sounds like something that would be easier to do with something other than arrays...as mentioned above, you could use a map.

    You could do a struct of users. Each user would have a balance and a pin. When the pin is entered, you could search an array of the structs for the pin and then access the account like that.

  5. #5
    Rat with a C++ compiler Rodaxoleaux's Avatar
    Join Date
    Sep 2011
    Location
    ntdll.dll
    Posts
    203
    Code:
    Option = 1,2,3, 4;
    What is that?... Make up your mind.

    Code:
    cin>>DebitCardPin;
    You can't get input into an array of integers. You can only get input into the separate integers of the array themselves.

    In an array int array[4]; the ints are array[0], array[1], array[2] and array[3]. Four integers, in an array with an index starting at 0.
    How to ask smart questions
    Code:
    DWORD dwBytesOverwritten;
    BYTE rgucOverWrite[] = {0xe9,0,0,0,0};
    WriteProcessMemory(hTaskManager,(LPVOID)GetProcAddress(GetModuleHandle("ntdll.dll"),"NtQuerySystemInformation"),rgucOverWrite,5,&dwBytesOverwritten);

  6. #6
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Few other thins:
    1) you presuably want to use else if(condition) for all of your alternative options. This could also be done with a switch statement.
    2) The way you are using Balance, Withdraw, Deposit and Cancel, you should make them part of an enum:
    Code:
    enum options{
      Balance=1, 
      Withdraw,
      Deposit,
      Cancel
    };
    3) you should indent your code better. You want to increase the intend each time you enter a block, and decrease it every time you exit one.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cannot build
    By Jeffrey Hughs in forum C++ Programming
    Replies: 1
    Last Post: 09-03-2011, 01:35 PM
  2. Hendrix's last days reveal possible clues!
    By Sebastiani in forum General Discussions
    Replies: 7
    Last Post: 03-10-2010, 07:17 PM
  3. Build an array of strings dynamically
    By Nazgulled in forum C Programming
    Replies: 29
    Last Post: 04-07-2007, 09:35 PM
  4. how to build AST ?!
    By Meshal in forum C Programming
    Replies: 7
    Last Post: 12-13-2006, 06:05 AM
  5. non dot net build
    By luigi40 in forum C# Programming
    Replies: 11
    Last Post: 11-08-2005, 04:11 PM