Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <fstream>
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- int main()
- {
- fstream file;
- int line_count = 0;
- int months;
- string name_file;
- std::cout << "Please input the file name for your report file: ";
- std::cin >> name_file;
- if (name_file != "load_report.txt")
- {
- std::cout << "Invalid report file!\n";
- exit(1);
- }
- std::cout << "Please provide the number of months to consolidate: ";
- std::cin >> months;
- if (months <= 0)
- {
- std::cout << "You need to have at least one month in order to"
- << " consolidate your sales.\n";
- exit(1);
- }
- std::cout << "\n";
- file.open(name_file, ios::in);
- if (file.is_open())
- {
- string line;
- while (getline(file, line))
- {
- line_count++;
- }
- }
- else
- {
- std::cout << "Could not open file!\n";
- exit(1);
- }
- file.close();
- file.open(name_file, ios::in);
- vector<float> a(line_count);
- int k = 0;
- if (file.is_open())
- {
- for (auto & val : a)
- {
- file >> val;
- }
- }
- else
- {
- std::cout << "Could not open file!\n";
- exit(1);
- }
- file.close();
- int loops = line_count / months;
- for (int i = 0; i < loops; ++i)
- {
- float sum = 0;
- std::cout << "Month ";
- for (int j = 0; j < months; ++j)
- {
- std::cout << i * months + j + 1 << " ";
- sum += a[i * months + j];
- }
- std::cout << "sales: $" << sum << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement