Advertisement
riggnaros

Cardealership loop

Oct 11th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.  
  11.     ifstream infile;
  12.     ofstream outfile;
  13.     double retailValue = 0;
  14.     double baseValue = 0;
  15.     double comission = 0;
  16.     int employeeID = 0;
  17.     int count = 0;
  18.     double totalSales = 0;
  19.     double totalComission = 0;
  20.     int previousID = 0;
  21.     double employeeComissions = 0;
  22.     double employeeSales = 0;
  23.  
  24.     infile.open("carsales.dat");
  25.     outfile.open("carsales.txt");
  26.     outfile << "WEEKLY SALES REPORT: ";
  27.     outfile << endl
  28.             << "Employee ID / Retail Value / Comission";
  29.     outfile << fixed << showpoint << setprecision(2);
  30.  
  31.     while (!infile.eof()) {
  32.  
  33.         infile >> employeeID >> retailValue >> baseValue;
  34.  
  35.         if (employeeID >= 100 && employeeID <= 999) {
  36.             count++;
  37.         }
  38.  
  39.         if ((baseValue * .3) > 100) {
  40.             comission = baseValue * .3;
  41.         }
  42.         else
  43.             comission = 100;
  44.  
  45.         if (previousID && previousID != employeeID) {
  46.             outfile << endl
  47.                     << "Totals for Employee ID: " << previousID << ' ' << "Total Comission: " << employeeComissions << ' ' << "Total Retail Value: " << employeeSales;
  48.             employeeComissions = 0;
  49.             employeeSales = 0;
  50.         }
  51.  
  52.         outfile << endl
  53.                 << employeeID << ' ' << retailValue << ' ' << comission << ' ';
  54.  
  55.         totalSales += retailValue;
  56.         totalComission += comission;
  57.         previousID = employeeID;
  58.         employeeComissions += comission;
  59.         employeeSales += retailValue;
  60.     }
  61.  
  62.     outfile << endl
  63.             << "Totals for Employee ID: " << employeeID << ' ' << "Total Comission: " << employeeComissions << ' ' << "Total Retail Value: " << employeeSales;
  64. outfile<<endl;
  65.     outfile << endl
  66.             << "Records: " << count;
  67.     outfile << endl
  68.             << "Total Sales: " << totalSales;
  69.     outfile << endl
  70.             << "Total Comission: " << totalComission;
  71.  
  72.     infile.close();
  73.     outfile.close();
  74.  
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement