Hi there! I was wondering if someone would be so kind as to look at my code and tell me how I can fix my output! My goal is to get the corresponding name, and the sales amount, that are highest for each Quarter of the Year. This is all MY code I made from scratch. Pretty proud of it. Would love to hear some criticism on anything I could do to make it prettier. Thanks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main( )
{
string name[3];
double sales[4][4];
int employeeNumber = 1;
int quarter = 1;
double highestSales = sales[0][0];
double highestSalesFirst;
double highestSalesSecond;
double highestSalesThird;
double highestSalesFourth;
cout.precision(2);
for (int i = 0; i < 3; i++)
{
cout << "Enter the name of employee " << employeeNumber << "." << endl;
cin >> name[i];
for (int j = 0; j < 4; j++)
{
cout << "Enter the sales for quarter " << quarter << "." << endl;
cin >> sales[i][j];
quarter++;
}
quarter = 1;
employeeNumber++;
}
cout << "\n" << endl;
cout << "Name 1st Quarter 2nd Quarter 3rd Quarter 4th Quarter" << endl;
cout << fixed << name[0] << " $" << sales[0][0] << " $" << sales[0][1] << " $" << sales[0][2] << " $" << sales[0][3] << endl;
cout << fixed << name[1] << " $" << sales[1][0] << " $" << sales[1][1] << " $" << sales[1][2] << " $" << sales[1][3] << endl;
cout << fixed << name[2] << " $" << sales[2][0] << " $" << sales[2][1] << " $" << sales[2][2] << " $" << sales[2][3] << endl;
for (int k = 0; k < 3; k++)
{
if( sales[k][0] > highestSalesFirst )
{
highestSalesFirst = sales[k][0];
}
}
for (int k = 0; k < 3; k++)
{
if( sales[k][1] > highestSalesSecond )
{
highestSalesSecond = sales[k][1];
}
}
for (int k = 0; k < 3; k++)
{
if( sales[k][2] > highestSalesThird )
{
highestSalesThird = sales[k][2];
}
}
for (int k = 0; k < 3; k++)
{
if( sales[k][3] > highestSalesFourth )
{
highestSalesFourth = sales[k][3];
}
}
cout << "\n" << endl;
cout << "1st: " << highestSalesFirst << endl;
cout << "2nd: " << highestSalesSecond << endl;
cout << "3rd: " << highestSalesThird << endl;
cout << "4th: " << highestSalesFourth << endl;
return 0;
}
|
Here's the output.
Enter the name of employee 1.
a
Enter the sales for quarter 1.
1000
Enter the sales for quarter 2.
2000
Enter the sales for quarter 3.
3000
Enter the sales for quarter 4.
4000
Enter the name of employee 2.
b
Enter the sales for quarter 1.
9000
Enter the sales for quarter 2.
2000
Enter the sales for quarter 3.
1000
Enter the sales for quarter 4.
5000
Enter the name of employee 3.
c
Enter the sales for quarter 1.
8594
Enter the sales for quarter 2.
2342
Enter the sales for quarter 3.
9089
Enter the sales for quarter 4.
9999
Name 1st Quarter 2nd Quarter 3rd Quarter 4th Quarter
a $1000.00 $2000.00 $3000.00 $4000.00
b $9000.00 $2000.00 $1000.00 $5000.00
c $8594.00 $2342.00 $9089.00 $9999.00
1st: 9000.00
2nd: 7905617923685723573105887288915988576119202615849845111286267071393744028657026093581182178249767099152164562614556854156253125994337485421054844259202620157417935557688907161167080693155052298608682970938133851611805634081492328534568951495379314389786621378560.00
3rd: 9089.00
4th: 9999.00
|
I need it to display:
Name 1st Quarter 2nd Quarter 3rd Quarter 4th Quarter
a $1000.00 $2000.00 $3000.00 $4000.00
b $9000.00 $2000.00 $1000.00 $5000.00
c $8594.00 $2342.00 $9089.00 $9999.00
b had the most sales at $9000.00 for quarter 1.
c had the most sales at $2342.00 for quarter 2.
c had the most sales at $9089.00 for quarter 3.
c had the most sales at $9999.00 for quarter 4.
|
Again, thank you for any help that is given!