Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using std::cout;
- using std::cin;
- using std::endl;
- using std::fixed;
- using std::setprecision;
- using std::setw;
- using std::left;
- int main()
- {
- double sales[4][5] = {
- {0,0,0,0,0},
- {0,0,0,0,0},
- {0,0,0,0,0},
- {0,0,0,0,0}
- };
- int salesPerson = 0;
- int product = 0;
- double value = 0;
- while(true) {
- cout << "Enter the salesperson, product, and total sales." << endl;
- cout << "(Enter -1 for the salesperon to end input): ";
- cin >> salesPerson;
- if(!cin || (salesPerson < 1 && salesPerson != -1) || salesPerson > 4) {
- cout << "Sales person should be between 1 and 4" << endl;
- continue;
- }
- else if(salesPerson == -1) {
- break;
- }
- cin >> product;
- if(!cin || product < 1 || product > 5) {
- cout << "Product should be between 1 and 5" << endl;
- continue;
- }
- cin >> value;
- if(!cin || value < 0) {
- cout << "Value should be a positive floating-point number" << endl;
- break;
- }
- sales[salesPerson-1][product-1] += value;
- }
- cout << setw(8) << left << "Sales" << setw(36) << left << "Products" << endl;
- cout << setw(8) << left << "Person";
- for(int i = 0; i < 5; i++) {
- cout << setw(8) << left << (i+1);
- }
- cout << setw(6) << left << "Total" << endl;
- double productsTotal[4] = {0,0,0,0};
- for(int i = 0; i < 4; i++) {
- cout << setw(8) << left << (i+1);
- double salesPersonTotal = 0;
- for(int j = 0; j < 5; j++) {
- salesPersonTotal += sales[i][j];
- productsTotal[j] += sales[i][j];
- cout << setw(8) << left;
- cout << fixed << setprecision(2) << sales[i][j];
- }
- cout << setw(6) << left << salesPersonTotal << endl;
- }
- cout << setw(8) << left << "Total";
- for(int i = 0; i < 5; i++) {
- cout << setw(8) << left;
- cout << fixed << setprecision(2) << productsTotal[i];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement