Advertisement
NewbProgrammer

Divisional Sales

Dec 17th, 2012
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdlib>
  3. #include<fstream>
  4. #include<sstream>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. const int SIZE = 12;
  10.  
  11. struct Division
  12. {
  13.       char divName[SIZE]; // Division name
  14.       double sales[4]; // Quarterly sales stored as an array
  15. };
  16.          
  17.  
  18.  
  19. int main()
  20. {
  21.        void Intro();
  22.        std::vector<Division> CreateCorporateFile();
  23.        void DisplayCorporateSales();
  24.        
  25.        Intro();
  26.        DisplayCorporateSales();
  27.        
  28.        
  29.        system("PAUSE");
  30.        return 0;
  31. }
  32.  
  33. void Intro()
  34. {
  35.      cout<<"This program will prompt you to enter in quarterly sales for "
  36.            "four different\ndivisions of a company.\n\n";
  37. }
  38.  
  39.  
  40. std::vector<Division> CreateCorporateFile()
  41. {
  42.     std::vector<Division> divArray;
  43.     Division div;
  44.     int x = 0;
  45.     for(int x = 0; x < 4; x++)
  46.     {
  47.     /*do {*/int quarter = 1;
  48.           cout << "Enter the name of the division: ";
  49.           cin >> div.divName;
  50.           for(int i = 0; i < 4; i++)
  51.           {
  52.                cout << "Enter in the sales for quarter "<< quarter <<": ";
  53.                cin >> div.sales[i];
  54.                if(div.sales[i] > 0)
  55.                {
  56.                     quarter++;
  57.                }
  58.                else
  59.                {
  60.                     cout << "Sales are not allowed to be negative.\n";
  61.                }
  62.           }
  63.        
  64.         divArray.push_back(div);
  65.         /*x++;
  66.     } while(x < 4);*/
  67. }
  68.     return divArray;
  69. }
  70.  
  71.      
  72.  
  73.  
  74. void DisplayCorporateSales()
  75. {
  76.      
  77.      Division div;
  78.      
  79.          std::vector<Division> divisions = CreateCorporateFile();
  80.     for (size_t i=0; i<divisions.size(); i++)
  81.     {
  82.         cout << "Here are the quarterly sales for " << divisions[i].divName
  83.         << ": \n";
  84.         Division div = divisions[i];
  85.         for(int j = 0, quarter = 1; j < 4; ++j, ++quarter)
  86.         {
  87.             cout << "Quarter "<< quarter << " sales: $"<< div.sales[j]
  88.             <<"\n";
  89.         }
  90.     }        
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement