Advertisement
Guest User

why isnt this working

a guest
Jul 9th, 2015
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.11 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<iomanip>
  4. #include<string>
  5. using namespace std;
  6. //global variables
  7. const int SIZE = 100;
  8. const char STAT[4] = "SMH";
  9. int counter = 0;
  10. int hw[SIZE], status[SIZE], empid[SIZE], payrate[SIZE];
  11. string firstname[SIZE], lastname[SIZE];
  12. float taxnet[SIZE];
  13. float taxwh[SIZE];
  14. float overtime[SIZE];
  15. float gross[SIZE];
  16. float bracket[SIZE];
  17. float taxes[SIZE];
  18. float net[SIZE];
  19. float overtimepay[SIZE];
  20. float RegGrossPay[SIZE];
  21. float ravg[SIZE];
  22.  
  23. //function prototype
  24. //data_entry(myFile, firstname, lastname, hw, status, empid, payrate, counter);
  25. void data_entry(char &);
  26. void payrollcalc(ofstream &);
  27. void data_recall(void);
  28.  
  29. //void payrollcalc(int counter, float employeenumber[counter], float manhours[counter], float payrate[counter], float status[counter]);
  30.  
  31. //main
  32. int main(){
  33.     char usercontrol;
  34.     //while (usercontrol != '4'){//delete
  35.     do{
  36.         cout << "Press 1 to enter more data press 2 to recall a data file press 4 to exit. ";
  37.         cin >> usercontrol;
  38.         //data entry
  39.         if (usercontrol == '1')
  40.             data_entry(usercontrol);
  41.         //data recall
  42.         else if(usercontrol == '2')
  43.             data_recall();
  44.         //choices: 1, 2, 4. other choice will rerun loop
  45.     }while (usercontrol != '4');
  46.     return 0;
  47. }
  48. //Data Entry
  49. void data_entry(char &usercontrol){
  50.     ofstream myFile("employee.payroll.txt", ios::out);
  51.     if(!myFile){
  52.         cout << "Cannot create file!!\nProgram terminating!!\n";
  53.         exit(0);
  54.     }
  55.     myFile << left << "DR. EBRAHIMI'S PAYROLL INSTITUTE\n\n";
  56.     myFile << "FIRST NAME     LAST NAME      STAT      SSN     HW      HR     OTH      OTP     REGP    GROSS   TAX      NET     Running avg\n";
  57.     myFile << "==========     =========      ====      ===     ==      ==     ===      ===     ====    =====   ===      ===     ===========\n";
  58.     do{
  59.         cout << "Enter employees first name: ";
  60.         cin >> firstname[counter];
  61.         cout << "Enter employees last name: ";
  62.         cin >> lastname[counter];
  63.         do{
  64.             cout << "Enter 1 for single, 2 for married, and 3 for head of household: ";
  65.             cin >> status[counter];
  66.             if(status[counter]>3 || status[counter]<1)
  67.                 cout << "Invalid option!\n";
  68.         }while(status[counter]>3 || status[counter]<1);
  69.         cout << "Enter Employee ID: ";
  70.         cin >> empid[counter];
  71.         cout << "Enter Number of Hours Worked: ";
  72.         cin >> hw[counter];
  73.         cout << "Enter Pay rate: ";
  74.         cin >> payrate[counter];
  75.         //payroll calculation
  76.         //do we need to pass down the index? maybe we need, double check afterwards
  77.         payrollcalc(myFile);
  78.         //payrollcalc(counter, employeenumber, manhours, payrate, status);
  79.         counter++;
  80.         do{
  81.             cout << "Press 1 to enter more data press 2 to recall a data file press 4 to exit. ";
  82.             cin >> usercontrol;
  83.         }while(usercontrol != '4' && usercontrol != '1' && usercontrol != '2');
  84.  
  85.     }while(usercontrol == '1');
  86.     myFile.close();
  87. }
  88. //payroll calculation
  89. //void payrollcalc(int counter, float employeenumber[counter], float manhours[counter], float payrate[counter], float status[counter]){
  90. void payrollcalc(ofstream &myFile){
  91.     if (hw[counter] > 40) {
  92.         overtime[counter] = (float)hw[counter] - 40;
  93.         overtimepay[counter] = (overtime[counter] * payrate[counter]) * 1.5;
  94.         RegGrossPay[counter] = (hw[counter]-overtime[counter]) * payrate[counter];
  95.         gross[counter] = overtimepay[counter] + RegGrossPay[counter];
  96.         //gross[counter] = ((hw[counter] - overtime[counter]) * payrate[counter]) + ((payrate[counter] * 1.5)* overtime[counter]);
  97.         ///overtime claculation
  98.     }
  99.     else {
  100.         RegGrossPay[counter] = gross[counter] = hw[counter] * payrate[counter];
  101.         ///no overtime calculation
  102.     }
  103.     if (gross[counter] > 1000){
  104.         taxnet[counter] = .7;
  105.         taxwh[counter] = .3;
  106.         bracket[counter] = 3;
  107.     }
  108.     else if (800<gross[counter]<=1000){
  109.         taxnet[counter] = .8;
  110.         taxwh[counter] = .2;
  111.         bracket[counter] =2;
  112.     }
  113.     else if(500<gross[counter]<=800){
  114.         taxnet[counter]= .9;
  115.         taxwh[counter]=.1;
  116.         bracket[counter] = 1;
  117.     }
  118.     else if(gross[counter]<= 500){
  119.         taxnet[counter] = 1;
  120.         taxwh[counter] = 0;
  121.         bracket[counter]= 0;
  122.     }
  123.     ///finds tax bracket
  124.     if (status[counter] == 1){
  125.         taxwh[counter] += .05;
  126.         taxnet[counter] -= .05;
  127.     }
  128.     else if(status[counter] == 2){
  129.         taxwh[counter] += 0;
  130.         taxnet[counter] -= 0;
  131.     }
  132.     else if(status[counter] == 3){
  133.         taxwh[counter] -= .05;
  134.         taxnet[counter] += .05;
  135.     }
  136.     //decides marital status
  137.     taxes[counter] = gross[counter] * taxwh[counter];
  138.     net[counter] = taxnet[counter] * gross[counter];
  139.    
  140.     for (int a = 0; a<counter; a++){
  141.        
  142.         float sum;
  143.         float temp = counter;
  144.         float temp2 = 0;
  145.         sum+=net[counter];
  146.         temp2 = temp +1;
  147.         ravg[counter] = sum/temp2;
  148.        
  149.        
  150.     }
  151.     //tax calc
  152.     /*
  153.     cout << " Your ID is                " << empid[counter] << endl;
  154.     cout << " # of hours worked         " << hw[counter] << endl;
  155.     cout << " Your Hourly rate is       " << payrate[counter] << endl;
  156.     cout << " Your Gross pay is         " << gross[counter] << endl;
  157.     cout << " Your tax bracket is       " << bracket[counter] << endl;
  158.     if (status[counter] == 1){
  159.     cout << " You are single your tax modifier is + 5% taxes" <<endl;
  160.     }
  161.     else if(status[counter] == 2){
  162.     cout << " You are married your tax modifier is 0% more taxes" <<endl;      
  163.     }
  164.     else if(status[counter] == 3){
  165.     cout << " You are head of household your tax modifier is - 5% taxes" <<endl;
  166.     }
  167.     cout << " Your tax rate is          " << taxwh[counter] << endl;
  168.     cout << " Amount of taxes           " << taxes[counter] << endl;
  169.     cout << " Your net pay is           " << net[counter] << endl;
  170.     */
  171.     myFile << left << setw(15) << firstname[counter] << setw(15) << lastname[counter];
  172.     myFile << setw(10) << status[counter] << setw(8) << empid[counter];
  173.     myFile << setw(8) << hw[counter] << setw(8) << payrate[counter];
  174.     myFile << setw(8) << overtime[counter] << setw(8) << overtimepay[counter];
  175.     myFile << setw(8) << RegGrossPay[counter] << setw(8) << gross[counter];
  176.     myFile << setw(8) << taxes[counter] << setw(8) << net[counter]<< setw(8) << ravg[counter] << endl;
  177.  
  178.  
  179.  
  180.     cout << left << "DR. EBRAHIMI'S PAYROLL INSTITUTE\n\n";
  181.     cout << "FIRST NAME     LAST NAME      STAT      SSN     HW      HR     OTH      OTP     REGP    GROSS   TAX      NET     Running avg\n";
  182.     cout << "==========     =========      ====      ===     ==      ==     ===      ===     ====    =====   ===      ===     ===========\n";
  183.     cout << left << setw(15) << firstname[counter] << setw(15) << lastname[counter];
  184.     cout << setw(10) << status[counter] << setw(8) << empid[counter];
  185.     cout << setw(8) << hw[counter] << setw(8) << payrate[counter];
  186.     cout << setw(8) << overtime[counter] << setw(8) << overtimepay[counter];
  187.     cout << setw(8) << RegGrossPay[counter] << setw(8) << gross[counter];
  188.     cout << setw(8) << taxes[counter] << setw(10) << net[counter] << setw(10) << ravg[counter] << endl;
  189.  
  190.  
  191.  
  192.     ///calc out put
  193.  
  194.     //std::string empnum = std::to_string(employeenumber[counter]);
  195.     //ofstream payroll(empnum + ".txt");
  196.     //writeWorkerInfo(payroll[counter], employeenumber[counter], manhours[counter], payrate[counter], gross[counter], taxwh[counter], taxes[counter], net[counter], bracket[counter], status[counter]);
  197.     ///sends up to write the file
  198.     /// The file automatically closes when you leave the function.
  199. }
  200. /*
  201. void writeWorkerInfo(ofstream &stream, int employeenumber, float manhours, float payrate, float gross, float taxwh, float taxes, float net, float bracket, float status){
  202. stream << " Your ID is                " << employeenumber << endl;
  203. stream << " # of hours worked         " << manhours << endl;
  204. stream << " Your Hourly rate is       " << payrate << endl;
  205. stream << " Your Gross pay is         " << gross << endl;
  206. stream << " Your tax bracket is       " << bracket << endl;
  207. if (status == 1){
  208. stream << " You are single your tax modifier is 5% more taxes" <<endl;
  209. }
  210. else if(status == 2){
  211. stream<< " You are married your tax modifier is 0% more taxes" <<endl;      
  212. }
  213. else if(status == 3){
  214.  
  215. stream << " You are head of household your tax modifier is 5% less taxes" <<endl;
  216.  
  217. }
  218. stream << " Your tax rate is          " << taxwh << endl;
  219. stream << " Amount of taxes           " << taxes << endl;
  220. stream << " Your net pay is           " << net << endl;
  221.  
  222. ///file is writen
  223. }
  224. */
  225. void data_recall(){
  226.     ifstream inputFile("employee.payroll.txt", ios::in);//not fstream dont need ios::in
  227.     if (!inputFile){
  228.         cout << "File does not exist!!\n";
  229.         cout << "Program terminating!!\n";
  230.         exit(1);//error
  231.     }
  232.     //file exist, first 3 line need to be removed
  233.     string buffer;
  234.     //reset counter
  235.     counter = 0;
  236.     while (getline(inputFile,buffer)){
  237.         cout << buffer;
  238.     }
  239.     cout << endl;
  240.     inputFile.close();
  241.     /*  string filename;//employeenumber[];
  242.     cout << "Enter employee number with txt at the end";
  243.     cin >> filename;
  244.     cin >> employeenumber[];
  245.  
  246.     ifstream payroll;
  247.     payroll.open(filename.c_str());
  248.  
  249.     //payroll <<
  250.     /*
  251.     Your ID is 1234
  252.     # of hours worked 123
  253.     Your Hourly rate is 15
  254.     Your Gross pay is 2467.5
  255.     Your tax bracket is 3
  256.     You are head of household your tax modifier is 5% less taxes
  257.     Your tax rate is 0.25
  258.     Amount of taxes 616.875
  259.     Your net pay is 1850.62
  260.     */
  261.     //payroll.close();
  262.     //payroll.open(employeenumber.c_str() );
  263.     ///I have no idea what going on here i would love soem feed back. the program apears to loop forever
  264.  
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement