Information is not passing to txt

This is a discussion on Information is not passing to txt within the C++ Programming forums, part of the General Programming Boards category; How come the information is not passing to txt file Code: PHP Code: void hotel :: submenu () {      information n ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    13

    Information is not passing to txt

    How come the information is not passing to txt file


    Code:
    PHP Code:
    void hotel::submenu() {     information n;     char choose;     int number=0;     int room;     char continues;     outfile.open (filename,ios::out|ios::app);          int single=100;     int doubler=200;     int triple=300;     cout<<"*******************"<<endl;     cout<<"Check In"<<endl;     cout<<"--------------- "<<endl;     cout<<"S->Single"<<endl;     cout<<"D->Double"<<endl;     cout<<"T->Triple"<<endl;     cout<<"Q->Quit "<<endl;     cout<<"*******************"<<endl;     cout<<"Enter the Type of Room you want: "<<endl;     cin>>choose;     cin.get();     choose=(char)toupper(choose);     n.type_room=choose;     int account_s=0;     int account_d=0;     int account_t=0;     int r_number;     char type;     string r_name;     string r_family;     string r_city;     string r_telephone;     int r_time;     double r_price;     if (choose=='S'||choose=='D'||choose=='T')         {             infile.open(filename,ios::in);             if (infile==NULL)             cout<<"Error opening the file"<<endl;             while(!infile.eof())             {                 infile>>r_number>>r_name>>r_family>>r_city>>r_telephone>>type>>r_price>>r_time;                 if(type=='S')                 {                     account_s++;                 }                 if (type=='D')                 {                     account_d++;                 }                 if (type=='T')                 {                     account_t++;                 }             }             single=single-account_s;             doubler=doubler-account_d;             triple=triple-account_t;             infile.close();             if (type=='S')             {                 single=single+1;             }             if (type=='D')             {                 doubler=doubler+1;             }             if (type=='T')             {                 triple=triple+1;             }             if (n.type_room=='S')             {                 if (single!=0)                 {                     cout<<"Total single bed available is "<<single;                     cout<<"\nHow many single bed you need?";                     cin>>number;                 }                 else                 {                     cout<<"\nSorry,No Room available.";                 }             }             if (n.type_room=='D')             {                 if (doubler!=0)                 {                     cout<<"Total double bed available is "<<doubler;                     cout<<"\nHow many double bed you need?";                     cin>>number;                 }                 else                 {                     cout<<"\nSorry,no room available.";                 }             }             if (n.type_room=='T')             {                 if (triple!=0)                 {                     cout<<"Total triple bed available is "<<triple;                     cout<<"\nHow many bed you need?";                     cin>>number;                 }                 else                 {                     cout<<"Sorry,no any room Available.";                 }             }             cin.get();             cout<<"First Name : ";             cin>>n.name;             cout<<"Family Name : ";             cin>>n.family;             cout<<"City : ";             cin>>n.city;             cout<<"Tel : ";             cin>>n.telephone;             cout<<"Charge :";             cin>>n.cost_perday;             cout<<"Days : ";             cin>>n.time;             int flag=0;             for (int i=1;i<=number;i++)             {                     cout<<"Room NO.: "<<endl;                 cin>>room;                 if (n.type_room=='S')                 {                     if(room<100 || room>199)                     {                         cout<<"You Should Choose The Number Between 100 And 199"<<endl;                         cout<<endl;                         i=i-1;                         continue;                     }                 infile.open(filename,ios::in);                 while (!infile.eof())                 {                         infile>>r_number>>r_name>>r_family>>r_city>>r_telephone>>type>>r_price>>r_time;                         if (room==r_number)                         {                                    cout<<"You Should Choose Other Room.This is occupied."<<endl;                             cout<<endl;                             flag=1;                             i=i-1;                             break;                         }                         else                         {                             flag=0;                         }                 }                 infile.close();                 if (flag==1)                 {                     continue;                 }                                  }                 if (n.type_room=='D')                 {                     if(room<200 || room>399)                     {                         cout<<"YOU Should Choose The Number Between 200 And 399"<<endl;                         cout<<endl;                         i=i-1;                         continue;                     }                  infile.open(filename,ios::in);                  while (!infile.eof())                     {                         infile>>r_number>>r_name>>r_family>>r_city>>r_telephone>>type>>r_price>>r_time;                         if (room==r_number)                         {                             cout<<"You must choose other room.This is occupied."<<endl;                             cout<<endl;                             flag=1;                             i=i-1;                             break;                         }                         else                         {                             flag=0;                         }                     }                                      infile.close();                     if (flag==1)                     {                         continue;                     }                     if (n.type_room=='T')                     {                         if(room<400 || room>499)                         {                             cout<<"You should Choose The Number Between 400 And 499"<<endl;                             cout<<endl;                             i=i-1;                             continue;                         }                     infile.open(filename,ios::in);                     while (!infile.eof())                     {                         infile>>r_number>>r_name>>r_family>>r_city>>r_telephone>>type>>r_price>>r_time;                         if (room==r_number)                         {                              cout<<"You Should choose other room.This is occupied."<<endl;                             cout<<endl;                             flag=1;                             i=i-1;                             break;                         }                         else                         {                             flag=0;                         }                     }                     infile.close();                     if(flag==1)                     {                         continue;                     }             }                       outfile.open (filename,ios::out|ios::app);             outfile<<room<<" ";             outfile<<n.name<<" ";                            outfile<<n.family<<" ";                            outfile<<n.city<<" ";                            outfile<<n.telephone<<" ";                           outfile<<n.type_room<<" ";                            outfile<<n.cost_perday<<" ";                           outfile<<n.time<<endl;                            outfile.close();                        }         cout<<"The Check In Is Finished"<<endl;         cout<<endl;         }         if (choose=='Q')         {             main();         }               cout<<"Another Check In (Y/N)"<<endl;     cin>>continues;     if(continues=='y'||continues=='Y')         main();     } } 

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    I suggest cutting down your program piece by piece ubntil you ifnd the error. Start with something like:
    Code:
    std::ofstream outfile("test.txt");
    outfile << "Can you see this?" << std::endl;
    outfile.close();
    and see if it works.

    I noticed you open outfile twice in your code, is that correct? If you temporarily close it in-between, I think you have to call the clear() method to nullify certain flags if set (may not be neccessary in your example, I dunno).
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    have you removed the filenames intentionally cos they dont seem to be initialised? they should probably give you errors in lines like this:

    Code:
    outfile.open (filename,ios::out|ios::app);
    Last edited by endo; 03-01-2005 at 07:53 AM.
    Couldn't think of anything interesting, cool or funny - sorry.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 07-07-2008, 07:48 AM
  2. how to get information from cpuid using c code
    By ZeroMemory in forum C Programming
    Replies: 2
    Last Post: 07-01-2008, 02:03 AM
  3. passing data
    By gvector1 in forum C# Programming
    Replies: 3
    Last Post: 10-17-2003, 09:39 AM
  4. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM
  5. using information from an array
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 12-07-2001, 04:30 PM

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