Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hi i am creating a program using C++ and it keeps giving errors...when you open the program a menu is suppose to appear and when you select option 1 it is suppose to show all the info in a file followed by other options...how ever that menu option isn't workin and neither is the option to store the info in the various files.
te code is:#include<iostream>
#include<fstream>
#include<string>
#include<cmath>using namespace std;
class PayRoll
{public:
int menu();
int option;
void employeeMenu();
void calPayMenu(double);
void calNisMenu(double);
void calITMenu(double);
int bankInfo(string,string,string,string);
int report(string, string);
private:
int emplyOption;
int emplySubMenuOption;
};int PayRoll::menu()
{
int choice;
system("cls"); //clears the screen
cout << "\n\t\tM E N U \n\n";
cout << "\t\tTreasure Beach Hotel Payroll System\n\n";
cout << "\t\tSelect the Employee [1]\n\n";
cout << "\t\tStore Info to Report [2] \n\n";
cout << "\t\tStore Bank Info [3]\n\n";
cout << "\t\tExit[4]\n\n";cout << "Enter menu option"<<endl;
cin >> choice;return choice;
}//------------------------------------------------------------------------------------------------------------
void PayRoll::employeeMenu()
{system("cls");
string idNum;
string name;
string nis;
double hrlyRate;
string bankAcctNum;
char period;string empId;
ifstream inFile;
inFile.open("F:\employeeInfoMajorProject.txt");
while(!inFile.eof())
{
inFile>>idNum>>name>>nis>>hrlyRate>>bankAcctNum>>period;cout<<idNum<<name<<nis<<hrlyRate<<bankAcctNum<<period;
}
inFile.close();cout<<"Please enter the person's ID number you would like"<<endl;
cin>>empId;while(!inFile.eof())
{
inFile>>idNum>>name>>nis>>hrlyRate>>bankAcctNum>>period;
if(idNum==empId)
{ inFile>>idNum>>name>>nis>>hrlyRate>>bankAcctNum>>period; }
}
cout<<idNum<<name<<nis<<hrlyRate<<bankAcctNum<<period;
cout << "\t\tCalculate Pay[1]\n\n";
cout << "\t\tCalculate N.I.S[2] \n\n";
cout << "\t\tCalculate Income Tax[3]\n\n";
cout << "\t\tReturn to main menu[4]\n\n";cout << "Choose an option from the above menu" <<endl;
cin >> emplySubMenuOption;;
switch(emplySubMenuOption)
{
case 1:{system ("cls");
calPayMenu(hrlyRate);
break;}
case 2:{system("cls");
calNisMenu( hrlyRate);
break;}
case 3:{system ("cls");
calITMenu(hrlyRate);
break;}
case 4:{system ("cls");
menu();
break;}
}}
//---------------------------------------------------------------------------------------
void PayRoll::calPayMenu(double hrlyRate)
{
double pay;
double PayOne;
int hrswk;
double taxPaid;
char period;
double Taxable;
double deductions;
double allowances;
double nonTaxable;
PayOne=hrlyRate*hrswk;
cout<< "Enter the hours worked:"<<endl;
cin >> hrswk;
cout<<"Please enter the total of any allowances which may be relevant to calculate the tax(such as travelling allowance):"<<allowances<<endl;
cin>>allowances;
cout<<"Please enter the total of any other deductions which may be relevant to calculate the tax"<<deductions<<endl;
cin>>deductions;
nonTaxable=allowances+deductions;
Taxable=PayOne-nonTaxable;
if(Taxable<24200/12)
{
taxPaid=Taxable * 0.20;
}
else
{
taxPaid=(Taxable*0.20)+(0.35*(Taxable-(24200/12)));
}
if (period=='W')
{
pay = (hrswk*hrlyRate) - (0.101 * (hrswk*hrlyRate));
cout<< "Weekly pay is :"<<pay<<endl;
}
else if((period=='M')&& ((hrswk*hrlyRate)>=2016.67))
{
pay=(hrswk*hrlyRate) - (0.101 * (hrswk*hrlyRate)+(taxPaid));// S
cout<<"Monthly pay after income tax is taken out is:"<<pay<<endl;
}//***end else} //
//-----------------------------------------------------------------------------------------------
void PayRoll::calNisMenu(double hrlyRate)
{
double nis;
int hrswk;cout << "The Selected Worker's hourly rate is: "<<endl;
cout << hrlyRate;
cout << "Enter the hours worked:"<<endl;
cin >> hrswk;nis= (hrswk*hrlyRate) - (0.101 * (hrswk*hrlyRate));
cout<<"The N.I.S for the selected person is:"<<nis<<endl;
}//-----------------------------------------------------------------------------------------------
int PayRoll::bankInfo(string idNum,string name,string bankAcctNum,string pay)
{
ofstream outFile;
outFile.open("C:/BankInfo.txt.");
if(!outFile.good())
cout<<"File could not be opened"<<endl;
else
{
outFile<<idNum<<name<<bankAcctNum<<pay;
}
outFile.close();
}
//-----------------------------------------------------------------------------------------------
void PayRoll::calITMenu(double hrlyRate)
{
double income;
double nontaxable;
double allowances;
double deductions;
double taxable;
double tax;
double hoursWrked;
cout<<"The Employees' hourly rate is:"<<hrlyRate<<endl;
cout<<"Please enter the hours the employee has worked"<<endl;
cin>>hoursWrked;
income=hrlyRate*hoursWrked;
cout<<"Please enter the total of any allowances(such as travelling allowance):"<<allowances<<endl;
cin>>allowances;
cout<<"Please enter the total of any other deductions which may be relevant"<<deductions<<endl;
cin>>deductions;
nontaxable=allowances+deductions;
taxable=income-nontaxable;
if(taxable<24200/12)
{
tax=taxable * 0.20;
}
else
{
tax=(taxable*0.20)+(0.35*(taxable-(24200/12)));
}
cout<<"Income Tax is"<<tax<<endl;
}//-----------------------------------------------------------------------------------------------
int PayRoll::report(string idNum,string name)
{
int sickDays;
cout<<"Please enter the sick days"<<endl;
cin>>sickDays;
ofstream outFile;
outFile.open("F:\BankInfo.txt.");
if(!outFile.good())
cout<<"File could not be opened"<<endl;
else
{
outFile<<idNum<<name<<sickDays;
}
outFile.close();
}//-----------------------------------------------------------------------------------------
int main()
{int Option1;
PayRoll menuopt;
Option1 = menuopt.menu();
while((Option1 !=0) && (Option1<= 5))
{
switch(Option1)
{
case 1:system ("cls");
menuopt.employeeMenu();
break;
case 2:system ("cls");
menuopt.report(string id,string n);
break;
case 3:system ("cls");
menuopt.bankInfo(string iD,string nM,string bA,string p);
break;
case 4:system ("cls");
cout << "You Are Now Leaving The Programme (Exit was Selected) " << endl;
break;
system("pause");
return 0;
} //end switch
cout<<"An Error has Occured"<<endl;
system("pause"); }
}

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |