Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int Months = 12;
- const int Years = 3;
- const char *months[Months] =
- {
- "Jan.", "Feb.", "March", "April", "May", "June",
- "July", "August", "Sept.", "October", "Nov.", "Dec."
- };
- int main() {
- cout << "This program prompts the user to input sales for an entire year, by month.";
- cout << "\nThe data will be stored in a multi-dimensional array, with a month string";
- cout << "\nrow and a double sales row.";
- double salesInput[Months];
- double totalSales[Years][Months];
- int yearCounter = 1;
- double sumYear1 = 0, sumYear2 = 0, sumYear3 = 0, totalSum = 0;
- do {
- cout << "\n\nPlease input the sales for year " << yearCounter;
- cout << "\nPlease enter all 12 sales with a space in between each month" << endl;
- for (int i=0; i<Months; i++)
- cin >> salesInput[i];
- for (int i=0; i<Months; i++)
- totalSales[yearCounter-1][i] = salesInput[i];
- yearCounter++;
- } while (yearCounter<4);
- cout << "\n\nYour current monthly sales are for year 1:\n";
- for (int month=0; month<Months; ++month)
- cout << months[month] << "\t";
- cout << endl;
- for (int i=0;i<Months; i++)
- cout << totalSales[0][i] << "\t";
- cout << "\n\nYour current monthly sales are for year 2:\n";
- for (int month=0; month<Months; ++month)
- cout << months[month] << "\t";
- cout << endl;
- for (int i=0;i<Months; i++)
- cout << totalSales[1][i] << "\t";
- cout << "\n\nYour current monthly sales are for year 3:\n";
- for (int month=0; month<Months; ++month)
- cout << months[month] << "\t";
- cout << endl;
- for (int i=0;i<Months; i++)
- cout << totalSales[2][i] << "\t";
- cout << endl;
- for (int i=0; i<Years; i++) {
- for (int j=0; j<Months; j++) {
- if (i==0)
- sumYear1 = totalSales[i][j] + sumYear1;
- if (i==1)
- sumYear2 = totalSales[i][j] + sumYear2;
- if (i==2)
- sumYear3 = totalSales[i][j] + sumYear3;
- }
- }
- cout << "\nThe total for year 1 is: " << sumYear1 << " Dollars";
- cout << "\nThe total for year 2 is: " << sumYear2 << " Dollars";
- cout << "\nThe total for year 3 is: " << sumYear3 << " Dollars";
- cout << "\nThe total sum for all three years is " << sumYear1 + sumYear2 + sumYear3 << " Dollars" << endl;
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment