problem in input of values, never ending loop starts.

i made this first project, but there are some problems. Cant fix it.
The problem is that when I enter two words e.g "notes payable" in liability particulars input or "salaries expence" in expence particulars input a never ending loop starts. I think the problem is with space. Help me out with this plz.... and plz help me improve this more...it will be a great thank full

#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<cstdlib>
class newaccount
{
public:
char company_name[90];
double no_owners,cap_owner,x;
void information()
{
cout<<"Enter Company Name"<<endl;
cin>>company_name;
cout<<"Enter Numbers Of Partners"<<endl;
cin>>no_owners;
for(x=1;x<=no_owners;x++)
{
cout<<"Enter capital for Owner "<<x<<endl;
cin>>cap_owner;
}


}

};
class liability
{
public:

void liability1()
{

ofstream record("liability.txt",ios::binary | ios::app);
if(!record)
{
cerr<<"File opening error"<<endl;
exit(1);
}
record<<"S.No\t\tParticulars\t\tBalance"<<endl<<endl;
struct transaction
{
int s_no;
char particular[100];
double balance;
};
transaction entry;
cout<<"##******** Liabilities ********##"<<endl;
cout<<"Enter Serial Number And Enter 0 To End Input"<<endl;
cin>>entry.s_no;
while(entry.s_no>0 && entry.s_no<=entry.s_no)
{
cout<<"Enter Particular \n";
cin>>entry.particular;
cout<<"Enter balance"<<endl;
cin>>entry.balance;
record.seekp((entry.s_no-1)*
sizeof(transaction));
record.write(reinterpret_cast<const char *>(&entry),sizeof(transaction));
cout<<"Enter S_No"<<endl;
cin>>entry.s_no;
record<<entry.s_no<<"\t\t"<<entry.particular<<"\t\t"<<entry.balance<<endl;
}


}


};
class assets
{
public:

void assets1()
{
ofstream record("assets.txt",ios::binary | ios::app);
if(!record)
{
cerr<<"File opening error"<<endl;
exit(1);
}
record<<"S.No\t\tParticulars\t\tBalance"<<endl<<endl;
struct transaction
{
int s_no;
char particular[100];
double balance;
};
transaction entry;
cout<<"##******** Assets ********##"<<endl;
cout<<"Enter Serial Number And Enter 0 To End Input"<<endl;
cin>>entry.s_no;
while(entry.s_no>0 && entry.s_no<=entry.s_no)
{
cout<<"Enter Particular \n";
cin>>entry.particular;
cout<<"Enter balance"<<endl;
cin>>entry.balance;
record.seekp((entry.s_no-1)*
sizeof(transaction));
record.write(reinterpret_cast<const char *>(&entry),sizeof(transaction));
cout<<"Enter S_No"<<endl;
cin>>entry.s_no;
record<<entry.s_no<<"\t\t"<<entry.particular<<"\t\t"<<entry.balance<<endl;
}

}

};
class oequity
{
public:
void oequity1()
{
ofstream record("O's Equity.txt",ios::binary | ios::app);
if(!record)
{
cerr<<"File opening error"<<endl;
exit(1);
}
record<<"S.No\t\tParticulars\t\tBalance"<<endl<<endl;
struct transaction
{
int s_no;
char particular[100];
double balance;
};
transaction entry;
cout<<"##******** Owner's Equity ********##"<<endl;
cout<<"Enter Serial Number And Enter 0 To End Input"<<endl;
cin>>entry.s_no;
while(entry.s_no>0 && entry.s_no<=entry.s_no)
{
cout<<"Enter Particular \n";
cin>>entry.particular;
cout<<"Enter balance"<<endl;
cin>>entry.balance;
record.seekp((entry.s_no-1)*
sizeof(transaction));
record.write(reinterpret_cast<const char *>(&entry),sizeof(transaction));
cout<<"Enter S_No"<<endl;
cin>>entry.s_no;
record<<entry.s_no<<"\t\t"<<entry.particular<<"\t\t"<<entry.balance<<endl;
}

}

};
class revenue
{
public:
void revenue1()
{
ofstream record("Revenue.txt",ios::binary | ios::app);
if(!record)
{
cerr<<"File opening error"<<endl;
exit(1);
}
record<<"S.No\t\tParticulars\t\tBalance"<<endl<<endl;
struct transaction
{
int s_no;
char particular[100];
double balance;
};
transaction entry;
cout<<"##******** Revenue ********##"<<endl;
cout<<"Enter Serial Number And Enter 0 To End Input"<<endl;
cin>>entry.s_no;
while(entry.s_no>0 && entry.s_no<=entry.s_no)
{
cout<<"Enter Particular \n";
cin>>entry.particular;
cout<<"Enter balance"<<endl;
cin>>entry.balance;
record.seekp((entry.s_no-1)*
sizeof(transaction));
record.write(reinterpret_cast<const char *>(&entry),sizeof(transaction));
cout<<"Enter S_No"<<endl;
cin>>entry.s_no;
record<<entry.s_no<<"\t\t"<<entry.particular<<"\t\t"<<entry.balance<<endl;
}

}


};
class expense:public newaccount,public liability,public assets,public oequity,public revenue
{
public:
void expense1()
{
ofstream record("Expenses.txt",ios::binary | ios::app);
if(!record)
{
cerr<<"File opening error"<<endl;
exit(1);
}
record<<"S.No\t\tParticulars\t\tBalance"<<endl<<endl;
struct transaction
{
int s_no;
char particular[100];
double balance;
};
transaction entry;
cout<<"##******** Expenses ********##"<<endl;
cout<<"Enter Serial Number And Enter 0 To End Input"<<endl;
cin>>entry.s_no;
while(entry.s_no>0 && entry.s_no<=entry.s_no)
{
cout<<"Enter Particular \n";
cin>>entry.particular;
cout<<"Enter balance"<<endl;
cin>>entry.balance;
record.seekp((entry.s_no-1)*
sizeof(transaction));
record.write(reinterpret_cast<const char *>(&entry),sizeof(transaction));
cout<<"Enter S_No"<<endl;
cin>>entry.s_no;
record<<entry.s_no<<"\t\t"<<entry.particular<<"\t\t"<<entry.balance<<endl;
}

}
void myswitch()
{
char ch;
cout<<"Enter character According to your requriment"<<endl;
cout<<"a --Liabilities"<<endl<<"b --Assets"<<endl<<"c --Owner's Equity"<<endl<<"d --Revenue"<<endl<<"e --Expense"<<endl<<"f --Exit"<<endl;
cin>>ch;
switch(ch)
{
case 'a':
liability1();
myswitch();
break;
case 'b':
assets1();
myswitch();
break;
case 'c':
oequity1();
myswitch();
break;
case 'd':
revenue1();
myswitch();
break;
case 'e':
expense1();
myswitch();
break;
case 'f':
exit(1);
default:
cout<<"Incorrect character Entered"<<endl;
}
}

};
main()
{

expense obj1;
obj1.information();
obj1.myswitch();

}
If you use cin>>, it will stop at whitespace. I recommend you change your char arrays to std::string's and use getline()
thanks zhuge....i did it, now the new problem is that it dosnt take the \n for enter.....means next function dosnt start unless 100 characters are given :(....

cin.getline(entry.particulars,100,'\n');

the \n is not exeptd... what can i do now :(
Topic archived. No new replies allowed.