Advertisement
andrefecto

infinite loop somewhere

Dec 2nd, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.77 KB | None | 0 0
  1. /*
  2.  
  3.  project5.cpp
  4.  
  5.  Andre Fecteau
  6.  
  7.  CSC135-101
  8.  
  9.  December 1, 2013
  10.  
  11.  This program will take in the name of the file and then process the information inside of the file
  12.  
  13.  */
  14.  
  15. #include <iostream>
  16.  
  17. #include <string>
  18.  
  19. #include <iomanip>
  20.  
  21. #include <fstream>
  22.  
  23. #include <cstdlib>
  24.  
  25. using namespace std;
  26.  
  27. /*
  28.  // Declarations
  29.  
  30.  // Initalizations
  31.  
  32.  // Input
  33.  
  34.  // Process
  35.  
  36.  // Output
  37.  
  38.  // Prolouge
  39.  */
  40. void instruct(){
  41.     cout <<"| ------------------------------------------------------------------------- |" << endl;
  42.     cout <<"| ------ Welcome to the employee pay and tax calculator ------------------- |" << endl;
  43.     cout <<"| ------------------------------------------------------------------------- |" << endl;
  44.     cout <<"This program will take the input of your filename that contains the:" << endl;
  45.     cout <<"Employee Name, then rate, then hours worked for Mon. to Friday on seperate" << endl;
  46.     cout <<"Lines respectively. Then do the math for the Net pay. Out this information" << endl;
  47.     cout <<"It will then do this until there is no more data left then quit." << endl;
  48.     cout << endl;
  49. }
  50. double name_hourly(ifstream &in){
  51.     string their_name = " ";
  52.     double hourly = 0.0;
  53.     getline (in, their_name);
  54.     in >> hourly;
  55.     return 0;
  56. }
  57. double hours_totaled(ifstream &in){
  58.     double monday = 0.0;
  59.     double tuesday = 0.0;
  60.     double wednesday = 0.0;
  61.     double thursday = 0.0;
  62.     double friday = 0.0;
  63.     double total = 0.0;
  64.  
  65.     in >> monday;
  66.     in >> tuesday;
  67.     in >> wednesday;
  68.     in >> thursday;
  69.     in >> friday;
  70.     total = monday + tuesday + wednesday + thursday + friday;
  71.  
  72. return total;
  73. }
  74. double doWork(double hours, double &hourly){
  75.     double pay_amount_gross = 0.0;
  76.     double pay_amount_net = 0.0;
  77.     double kept_precentage = 0.0;
  78.     double pay_kept = 0.0;
  79.  
  80.     pay_amount_gross = hours*hourly;
  81.     if(pay_amount_gross < 500){kept_precentage = 23.7;}
  82.     if(pay_amount_net >= 500){kept_precentage = 33.9;}
  83.     pay_kept = kept_precentage / pay_amount_gross * 100;
  84.     pay_amount_net = pay_amount_gross - pay_kept;
  85.     return 0;
  86. }
  87. void outInfo(double &pay_amount_gross, string &their_name, double &hourly, double hours, double &pay_amount_net, double &pay_kept){
  88.     cout <<"| ------------------------------------------------------------------------- |" << endl;
  89.     cout <<"| ----------------------- Calculation Totals ------------------------------ |" << endl;
  90.     cout <<"| ------------------------------------------------------------------------- |" << endl;
  91.     cout <<" Employee Name: " << their_name << endl;
  92.     cout <<"     Gross Pay: $" << setprecision(2)<< fixed << pay_amount_gross << endl;
  93.     cout <<"   Amount Kept: $"<< setprecision(2)<< fixed << pay_kept << endl;
  94.     cout <<"       Net Pay: $"<< setprecision(2)<< fixed << pay_amount_net << endl;
  95. }
  96. string file(double &pay_amount_gross, string &their_name, double &hourly, double hours, double &pay_amount_net, double &pay_kept){
  97. ifstream in;
  98.         while (true)
  99.             {
  100.                 string infilename;
  101.                 cout << "Please Enter the name of the file to be opened: ";
  102.                 getline( cin, infilename);
  103.                 in.open( infilename.c_str() );
  104.                 if(in)break;
  105.             }
  106.         if(in)
  107.             {
  108.             while(!in.eof())
  109.                 {
  110.                     name_hourly(in);
  111.                     hours_totaled(in);
  112.                     doWork(hours, hourly);
  113.                     outInfo(pay_amount_gross, their_name, hourly, hours, pay_amount_net, pay_kept);
  114.                 }
  115.             }
  116. return 0;
  117. }
  118. int main(){
  119.     double pay_amount_gross;
  120.     string their_name;
  121.     double hourly;
  122.     double hours;
  123.     double pay_amount_net;
  124.     double pay_kept;
  125.  
  126.  instruct();
  127.  file(pay_amount_gross, their_name, hourly, hours, pay_amount_net, pay_kept);
  128. return 0;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement