C++ the code below jus won't wrk y???

May 14, 2009 at 15:00:16
Specs: Windows Vista
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.

the 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"); }

}


See More: C++ the code below jus wont wrk y???

Report •


#1
May 14, 2009 at 17:32:09
Do you have a program specification that you could post? I'm not a c/c++ guru or anything but I'm confused by what you're trying to do with the class you've declared.

Here's a few things that I've noticed.

When you call the menu, you're not checking the menu function for invalid input. You don't really want to operate on a var that may be erroneous. For example, a user inputting an 'A' instead of a numeric value. Likewise, you should prompt for a valid menu option from within the menu function member until it's valid for your available options. When it is, return the value.

You've got a number of incorrect function calls. You define the data type in the prototype and / or declaration, but not the actual call. For example

case 2:system ("cls");
menuopt.report(string id,string n);

break;

The above is incorrect... you want menuopt.report(id, n);; however, you haven't declared id or n from within main or made them global that I picked up on.

You've got a couple of functions where return values are declared, but you aren't returning anything.

Your file paths need \\ in them. If you're not accepting user input file names, you might consider making those constant.

const char OUTFILE[] = "f:\\somepath\\somefile.txt";

If you're having compiler errors, comment out function calls and work with one problem until it's resolved, and then move on to the next. That way, you' won't be overwhelmed by a lot of errors and warnings.

Good luck.

______________________
My work in progress. I hate JS. :P


Report •

#2
May 14, 2009 at 18:00:06
ok thank u vry much...how ever when you first selsect option 1 in the first menu it is suppose to display the content of the employeeInfoMajorProject.txt on the screen but when i select that it just shows continuous numbers on the screen

Report •

#3
May 14, 2009 at 20:19:42

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; }
}

The above block looks like it could be a problem. You've closed the input file, but then try to read it again. If you want to poke around in the file, clear the eof bit and reset the cursor.

inFile.open("f:\\employeeInfoMajorProject.txt");
assert(inFile.is_open());

loop to read {
  ...
}

inFile.clear();
inFile.seekg(0, ios::beg);

loop to read {
   ...
}

inFile.close();

I didn't look that closely at your var declarations, but if you're reading data into the wrong var type, then your program may go loopy. As a safeguard, imo, you should always read data into a char[] or string data type and then use the appropriate conversion function to store each var as required. At this stage, you might wish to add assert(inFile.good()); where ever you're reading file data. For assert, you may need to add #include <cassert>

I really do encourage you to work on one task at a time in a simple program so that you can see if your file is being opened, read, and displays the correct data. Once that checks out, place the code within your class function member.

Good luck

______________________
My work in progress. I hate JS. :P


Report •

Related Solutions

#4
May 14, 2009 at 20:25:09
it is telling me in assert there is no such file or directory

Report •

#5
May 14, 2009 at 20:31:53
#include<iostream>
#include<fstream>
#include<string>
#include<cmath>
#include<cassert>

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");

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:\\MajorProject\\employeeInfoMajorProject.txt");

assert(inFile.is_open());


while(!inFile.eof())
{
inFile>>idNum>>name>>nis>>hrlyRate>>bankAcctNum>>period;

cout<<idNum<<name<<nis<<hrlyRate<<bankAcctNum<<period;

}
inFile.clear();
inFile.seekg(0, ios::beg);

cout<<"Please enter the person's ID number you would like"<<endl;
cin>>empId;

while(!inFile.eof())
{
inFile>>idNum>>name>>nis>>hrlyRate>>bankAcctNum>>period;

}
inFile.close();
{
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));
cout<<"Monthly pay after income tax is taken out is:"<<pay<<endl;


}
}

//-----------------------------------------------------------------------------------------------

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("F:\\MajorProject\\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:\\MajorProject\\Reports.txt.");
if(!outFile.good())
cout<<"File could not be opened"<<endl;
else
{
outFile<<idNum<<name<<sickDays;
}
outFile.close();
}

//-----------------------------------------------------------------------------------------

int main()
{

int Option1;
string id;
string n;
string iD;
string nM;
string bA;
string p;

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(id,n);
break;

case 3:system ("cls");
menuopt.bankInfo(iD, nM, bA, p);

break;

case 4:system ("cls");
cout << "You Are Now Leaving The Programme (Exit was Selected) " << endl;

break;




system("pause");
return 0;

}

cout<<"An Error has Occured"<<endl;
system("pause"); }



}

i did what you said but it still acts funny and scrambles the info on the screen...any more ideas?


Report •

#6
May 14, 2009 at 21:13:01
Post the contents to each of your data files. Without knowing what is being read, I couldn't say why it's bombing. My guess would be the stream is choking on trying to store data in the wrong var type, but it could be something else.

______________________
My work in progress. I hate JS. :P


Report •

#7
May 14, 2009 at 21:18:36
as for the other two files they are empty because the calculated data is to be stored there.


for the employeeInfoMajorProject the info is...it goes across in rows like a table:


560222-2013 Jason Boyce 325928 7.50 163738 W
780507-0213 David Haynes 229808 11 281819 M
520820-0156 Samantha Johnson 105478 6.75 238192 W
591225-0489 Tshani Blackette 110987 8 217283 M
481025-0100 Shaniqua Jones 100500 5.50 492045 W
891115-0087 Tshara Davis 350125 11 742833 M
890108-0098 Rochelle Beckles 324601 5.50 434223 W
860906-2000 David Small 300050 11 363464 M
791022-0232 Shakira Evans 290405 8 364636 M
690628-0800 Danika Jones 180546 6.75 675745 W
500227-0202 Josiah Bostick 104892 10 124364 M
551201-0140 Jamal Brown 120460 11 645262 M
700218-0501 Nicole Simpson 208679 5.50 896590 W
880414-0208 Elijah Hackette 310864 6.75 095847 W
650414-0140 Philip Skeete 298476 6.75 636364 W
790620-0065 Ajani Johnson 301481 11 634656 M


Report •

#8
May 14, 2009 at 21:30:43
#include<iostream>
#include<string>
#include<cmath>

using namespace std;


int option;
int employeeMenu();
void employeeSalary();
int displayFood();

int employeeMenu()
{
int employeeoption;


cout << "\t\t CADOGAN'S SERVICES MINIATURE GOLF COURSE\n\n";
cout << "\t\t[1.]Calculate Employee Salary\n\n";
cout << "\t\t[2.]Exit\n\n";

cout << "Enter employee option:";
cin >> employeeoption;

return employeeoption;
}
//--------------------------------------------------------------------------------------
void employeeSalary()
{
system("cls");
string name,dummy;
//employee name
double hours,rate,pay,code;
//count the employees
cout.setf(ios::fixed,ios::floatfield);
cout.precision(2);
//set decimal precision
cout << "Please enter an employee code (between 100 and 200 inclusively): ";
cin >> code;
while (code < 100 ||code > 201)
{
cout<<"Invalid Employee Code!"<<endl;
system("pause");
system("cls");
cout << "Please enter an employee code(between 100 and 200 inclusively): ";
cin >> code;
}
getline(cin, dummy);
cout << "Please enter an employee name: ";
getline(cin, name);
//read name
cout << "Please enter the hours worked: ";
cin >> hours;
//read hours worked
cout << "Please enter the rate of pay: ";
cin >> rate;
//read rate of pay
pay = hours * rate;
//calculate pay
cout << " "<<endl;
cout << " "<<endl;
cout << "Employee:" << name <<endl;
cout<<"Employee Earning: $" << pay << endl;
system("pause");
system("cls");
}
void fish()
{
double fishQuant;
double fishTotal;
cout<<"How many fish do you want:";
cin >>fishQuant;
fishTotal=fishQuant*8.00;
cout<<"Total Cost:$"<<fishTotal<<endl;

}
void hot()
{
double hotQuant;
double hotTotal;
cout<<"How many hotdogs do you want:";
cin>>hotQuant;
hotTotal=hotQuant*4.50;
cout<<"Total Cost:$"<<hotTotal<<endl;


}

void chick()
{
double chickQuant;
double chickTotal;
cout<<"How many chicken an chips do you want:";
cin>>chickQuant;
chickTotal=chickQuant*7.00;
cout<<"Total Cost:$"<<chickTotal<<endl;

}


void sand()
{
double sandQuant;
double sandTotal;
cout<<"How many sandwiches do you want:";
cin>>sandQuant;
sandTotal=sandQuant*3.95;
cout<<"Total Cost:$"<<sandTotal<<endl;

};

void drnk()
{
double drnkQuant;
double drnkTotal;
cout<<"How many drinks do you want:";
cin>>drnkQuant;
drnkTotal=drnkQuant*2.00;
cout<<"Total Cost:$"<<drnkTotal<<endl;

}
void display()
{

int options;
cout<<" Welcome to Cadogan's Services Minature Golf Course!"<<endl;
cout<<"Please continue to make all your selections by using the item number on the left"<<endl;
cout<<"When you are finished type '6' to exit."<<endl;
cout<<endl;
cout<<"NOTE: Any selection other than Item# or '6' will result in a crash"<<endl;
cout<<endl;
cout<<" MENU "<<endl;
cout<<"Item# Description Price"<<endl;
cout <<endl;
cout<<"[1] Fish And Chips 8.00"<<endl;
cout<<endl;
cout<<"[2] Hotdogs 4.50"<<endl;
cout<<endl;
cout<<"[3] Chicken And Chips 7.00"<<endl;
cout<<endl;
cout<<"[4] Sandwiches 3.95"<<endl;
cout<<endl;
cout<<"[5] Drinks 2.00"<<endl;
cout<<endl;
cout<<"[6] Exit " <<endl;
cout<<endl;
cout << "Enter option:";
cin >> options;


while (options > 8)
{
cout<<"Invalid Option!"<<endl;
system("pause");
system("cls");
cout<<" Welcome to Cadogan's Services Minature Golf Course!"<<endl;
cout<<"Please continue to make all your selections by using the item number on the left"<<endl;
cout<<"When you are finished type '6' to exit."<<endl;
cout<<endl;
cout<<"NOTE: Any selection other than Item# or '6' will result in a crash"<<endl;
cout<<endl;
cout<<" MENU "<<endl;
cout<<"Item# Description Price"<<endl;
cout <<endl;
cout<<"[1] Fish And Chips 8.00"<<endl;
cout<<endl;
cout<<"[2] Hotdogs 4.50"<<endl;
cout<<endl;
cout<<"[3] Chicken And Chips 7.00"<<endl;
cout<<endl;
cout<<"[4] Sandwiches 3.95"<<endl;
cout<<endl;
cout<<"[5] Drinks 2.00"<<endl;
cout<<endl;
cout<<"[6] Exit " <<endl;
cout<<endl;
cout << "Enter option: ";
cin >> options;

}
system("cls");
if (options == 1)
fish();
else
if (options == 2)
hot();
else
if (options == 3)
chick();
else
if (options == 4)
sand();
else
if (options == 5)
drnk();
//endifs
system("pause");
system("cls");

}
//-----------------------------------------------------------------------------------------
void displayMenu()
{

cout << "\n\t\t MAIN M E N U \n\n";
cout << "\t\t CADOGAN'S SERVICES MINIATURE GOLF COURSE\n\n";
cout << "\t\tEmployee Salary[1] \n\n";
cout << "\t\tFood Sales[2]\n\n";


}
//-----------------------------------------------------------------------------------------
int displaySelection(int opt)
{
int menu;
if (opt == 1)
menu = employeeMenu();
else
if (opt == 2)
display();
menu = 2 ;
return menu;
//end ifs


}

//-----------------------------------------------------------------------------------------
int main()
{

int menu;
int choice;
displayMenu();
cout << "Enter menu option:";
cin >> choice;
system("cls");

while (choice !=1 && choice != 2)
{
cout<<"Invalid Option Nubmber";
displayMenu();
cout << "Enter menu option:";
cin >> choice;
system("cls");
}
menu = displaySelection(choice);
if (menu == 1)
{
employeeSalary();
menu = employeeMenu();
}
else
if (menu == 2)
{

display();
}

system("PAUSE");
return 0;
}
//------------------------------------------------------------------------------------------------------------
my program is not executing as it should the 1st option should display the employee menu where you would then hit 1 and a sub menu to calculate the employee salary is to come up however the food sales menu is coming up


Report •

#9
May 14, 2009 at 22:50:02
Ok, looks like you're problem is how you're storing the data.

inFile>>idNum>>name>>nis>>hrlyRate>>bankAcctNum>>period;
560222-2013 Jason Boyce 325928 7.50 163738 W

the above has 7 fields, but you're trying to store them as 6.

idNum = 560222-2013 (string)
name = Jason (string)
nis = Boyce (string)
hrlyRate = 325928 (double)... oops
bankAcctNum = 7.50 (string)... oops
period = 163738 (char)... oops
W = ?? left in input field... oops

______________________
My work in progress. I hate JS. :P


Report •

#10
May 14, 2009 at 23:01:14
THANK YOU SO MUCHHH!...however it is displaying all clogged together and the calculations aren't working correctly...plz help pini she is also in my class and needs help...srry for over working you but thank you very much

Report •

#11
May 14, 2009 at 23:17:38
oh and i am having problems retuning to the main menu to decide if to store the info i calculated in pay and where to store it...and problem exiting the program....and also deciding to return to employee menu and selecting sa different employee without exiting the program

Report •

#12
May 15, 2009 at 00:05:17
now every id number i enter selects the last employee and not the requested employee.

#include<iostream>
#include<fstream>
#include<string>
#include<cmath>
#include<cassert>

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,string);
int report(string,string, string);

private:

int emplyOption;
int emplySubMenuOption;

};

int PayRoll::menu()
{
int choice;
system("cls");

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 lname;
string nis;
double hrlyRate;
string bankAcctNum;
char period;

string empId;

ifstream inFile;
inFile.open("F:\\MajorProject\\employeeInfoMajorProject.txt");

assert(inFile.is_open());


while(!inFile.eof())
{
inFile>>idNum>>name>>lname>>nis>>hrlyRate>>bankAcctNum>>period;

cout<<" "<<idNum<<" "<<name<<" "<<lname<<" "<<nis<<" "<<hrlyRate<<" "<<bankAcctNum<<" "<<period<<endl;

}
inFile.clear();
inFile.seekg(0, ios::beg);

cout<<"Please enter the person's ID number you would like to (the ID number is the first set of numbers displayed e.g : 560322-2013)"<<endl;
cin>>empId;

while(!inFile.eof())
{
inFile>>idNum>>name>>lname>>nis>>hrlyRate>>bankAcctNum>>period;

}
inFile.close();
{
if(idNum==empId)
{ inFile>>idNum>>name>>lname>>nis>>hrlyRate>>bankAcctNum>>period; }
}

system ("cls");

cout<<" "<<idNum<<" "<<name<<" "<<lname<<" "<<nis<<" "<<hrlyRate<<" "<<bankAcctNum<<" "<<period<<endl;;

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));
cout<<"Monthly pay after income tax is taken out is:"<<pay<<endl;


}

}

//-----------------------------------------------------------------------------------------------

void PayRoll::calNisMenu(double hrlyRate)
{

double nis;

int hrswk;

cout << "The Selected Worker's hourly rate is: "<<hrlyRate<<endl;
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;

cout << "\t\tExit and return to main menu [1]\n\n";
cout << "\t\tExit and return to main menu[2]\n\n";


}


//-----------------------------------------------------------------------------------------------


int PayRoll::bankInfo(string idNum,string name,string lname,string bankAcctNum,string pay)
{
ofstream outFile;
outFile.open("F:\\MajorProject\\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,string lname)
{
int sickDays;

cout<<"Please enter the sick days"<<endl;
cin>>sickDays;

ofstream outFile;
outFile.open("F:\\MajorProject\\Reports.txt.");
if(!outFile.good())
cout<<"File could not be opened"<<endl;
else
{
outFile<<idNum<<name<<lname<<sickDays;
}
outFile.close();
}

//-----------------------------------------------------------------------------------------

int main()
{

int Option1;
string id;
string n;
string iD;
string nM;
string bA;
string p;
string ln;
string lN;

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(id,n,ln);
break;

case 3:system ("cls");
menuopt.bankInfo(iD, nM,lN, bA, p);

break;

case 4:system ("cls");
cout << "You Are Now Leaving The Programme (Exit was Selected) " << endl;






system("pause");
return 0;

}

cout<<"An Error has Occured"<<endl;
system("pause"); }



}


Report •

#13
May 15, 2009 at 20:22:57
Back for more mischief are you? :P

The other program, pini's, is a bit hard to follow; displaySelection doesn't seem to be needed from what I could tell as it essentially does the same thing as the functions it calls. I sort of got lost after following a few function calls, but the problem *may* be returning a different menu value than expected, so it in return calls the wrong selection.

For post #11, if you wish to return the starting menu, call the menuopt.menu() again. You might want to retool the class a bit, so that you've got better flow.

For post#12, you need to compare the ids during the file read loop... perhaps something similar to

cout<<"Please enter the person's ID number
you would like to (the ID number is the
first set of numbers displayed e.g : 560322-2013)"<<endl;
cin>>empId;

while(!inFile.eof())
{   inFile>>idNum>>name>>lname>>nis>>hrlyRate>>
bankAcctNum>>period;

   if(idNum == empId) {
      
      cout << "Record: " << idNum 
           << "  " << name << "  "
           << lname << "  " << nis
           << "  " << hrlyRate << "  "
           << bankAcctNum << "  "
           << period;
   }
}

______________________
My work in progress. I hate JS. :P


Report •

#14
May 16, 2009 at 09:13:37
thnk u

Report •


Ask Question