CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Threaded View

  1. #1
    Join Date
    Dec 2010
    Posts
    4

    VBC++ help with putting stuff into a file

    Code:
    #include <iostream>
    #include <cmath>
    #include <cstring>
    #include <cstdlib>
    #include <ctime>
    #include <fstream>
    using std::ifstream;
    using std::ofstream;
    using namespace std;
    const int MAXACCOUNTS = 50;
    const int MAXANYTHING=100;
    ifstream myfile;
    ofstream myfile2;
    
    struct BankAccount{
     char Name[MAXANYTHING];
     char Address[MAXANYTHING];
     float Balance;
     int AccountNumber;
    };
    
    void menu(){
     cout<<"Welcome To The Bank Menu:"<<endl;
     cout<<"1. Open new account"<<endl;
     cout<<"2. Deposit amount"<<endl;
     cout<<"3. Withdraw amount"<<endl;
     cout<<"4. Display an account"<<endl;
     cout<<"5. Modify an account"<<endl;
     cout<<"6. Close an account"<<endl;
     cout<<"7. Exit"<<endl<<endl<<endl;
     cout<<"Please Select An Option:"<<endl;
    }
    
    void enter(BankAccount Account[], int & numberItems){
     const int LENGTH=20;
     
     int random_integer;
    
     if(numberItems==MAXACCOUNTS){
      cout<<"Can't add a new account. Array is full"<<endl;}
     BankAccount anAccount;
     cout<<endl<<"Please enter your name:"<<endl;
     cin>>anAccount.Name;
     cout<<endl<<"Please enter your address:"<<endl;
     cin>>anAccount.Address;
     cout<<endl<<"Please enter your initial deposit amount:"<<endl;
     cin>>anAccount.Balance;
    
     srand((unsigned)time(0));
     random_integer = rand();
     anAccount.AccountNumber = random_integer;
     cout<<"Your Account Number Is:"<< random_integer<<endl;
    
     Account[numberItems]=anAccount;
     numberItems++;
     }
    
    void display(BankAccount Account[],int & numberItems){
     int AccNum;
     
    
      if(numberItems==0)
       cout<<"There are no accounts in the bank.";
      else
       cout<<"Please enter the bank account number";
       cin>>AccNum;
       for(int k=0;k<=numberItems;k++){
        if(AccNum==Account[k].AccountNumber){
         cout<<"Account Name:"<<Account[k].Name<<endl;
         cout<<"Account Address:"<<Account[k].Address<<endl;
         cout<<"Account Balance:"<<Account[k].Balance<<endl;
        }
       }
    }
    
    
    
    //int MenuChoice, NextFreeAccount=0;
    //int AccountNumber [MAXACCOUNTS];
    //char Name[MAXACCOUNTS];
    //char Address [MAXACCOUNTS];
    //double deposit=0,withdraw=0;
    //int random_integer=0;
    
    
    
    
    
    
    
    void main(){
     int numberElements=10;
     BankAccount Accountss[MAXACCOUNTS];
     int selection;
     do{
      menu();
      cin>>selection;
      switch(selection){
       case 1:
        enter(Accountss,numberElements);
        break;
       case 2:
        display(Accountss,numberElements);
        break;
       case 3:
        //modify(Accountss,numberElements);
        break;
       case 4:
        //deleteItem(Accountss,numberElements);
        break;
      }
    
      myfile.open("File1.txt",ios::app);
      myfile2.open("File2.txt");
      if(myfile.fail()){
    	  cout<<"file1 could not be opened"<<endl;
      }
      else {
    	  cout<<"File1 was opened."<<endl;
      }
      if(myfile2.fail()){
    	  cout<<"File2 could not be opened"<<endl;
      }
      else{
    	  cout<<"file2 was opened"<<endl;
      }
    
     }while(selection!=5);
     cout<<"Thank you for using this program\n";
     system("pause");
    }
    thats our code..


    im just confused.. ssee i want to find out how to put the structure into the file.. so that it saves the users info. any help would be awesome.

    If you could leave your msn messenger address that would be awesome to help us.
    Last edited by cilu; December 7th, 2010 at 05:35 AM. Reason: code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured