#include <iostream>
using std::cin;
using std::cout;
using std::endl;
using std::ios;
#include <iomanip>
using std::fixed;
using std::setw;
using std::setprecision;
using std::showpoint;
int main()
{
const int PEOPLE = 5;
const int PRODUCTS = 6;
int sales[5][6]={{1},{2},{3},{4}};
double value;
double totalSales;
double productSales[ PRODUCTS ] = { 0.0 };
int salesPerson;
int product;
cout << "Enter the salesperson (1 - 4), product number (1 - 5), and "
<< "total sales.
Enter -1 for the salesperson to end input.
";
cin >> salesPerson;
while ( salesPerson != -1 )
{
cin >> product >> value;
value++;
cin >> salesPerson;
} // end while
cout << "
The total sales for each salesperson are displayed at the "
<< "end of each row,
" << "and the total sales for each product "
<< "are displayed at the bottom of each column.
" << setw( 12 )
<< 1 << setw( 12 ) << 2 << setw( 12 ) << 3 << setw( 12 ) << 4
<< setw( 12 ) << 5 << setw( 13 ) << "Total
" << fixed << showpoint;
for ( int i = 1; i < 4; i++ )
{
totalSales = 0.0;
cout << i;
for ( int j = 1; j < 5; j++ )
{
++ totalSales;
cout << setw( 12 ) << setprecision( 2 ) << sales[ i ][ j ];
+= productSales ;
} // end for
cout << setw( 12 ) << setprecision( 2 ) << totalSales << '
';
} // end for
cout << "
Total" << setw( 8 ) << setprecision( 2 )
<< productSales[ 1 ];
// display total product sales
for ( int j = 2; j < totalSales; j++ )
cout << setw( 12 ) << setprecision( 2 ) << productSales[ j ];
cout << endl;
return 0; // successful termination
} // end main
view sourceprint?
01
#include <iostream>
02
using std::cin;
03
using std::cout;
04
using std::endl;
05
06
#include <conio.h>
07
08
#include <iomanip>
09
using std::fixed;
10
using std::setw;
11
using std::setprecision;
12
using std::showpoint;
13
14
int main()
15
{
16
const static int PEOPLE = 5; //number of sales people (4)
17
const static int PRODUCTS = 6; //number of different products (5)
18
19
int sales[5][6] = {{1, 2, 3, 4}, {1, 2, 3, 4, 5}};
20
double value;
21
double totalSales;
22
double productSales[PRODUCTS] = {0.0};
23
int salesPerson;
24
int product;
25
26
cout << " Enter the salesperson's number (1-4), the product number (1-5), and total product sales.
"
27
<< "Enter -1 for salesperson to end input.
";
28
cin >> salesPerson;
29
30
while (salesPerson != -1)
31
{
32
cin >> product >> value;
33
34
value++;
35
36
cin >> salesPerson;
37
}
38
39
cout << "
The total sales for each salesperson are displayed at the "
40
<< "end of each row,
" << "and the total sales for each product "
41
<< "are displayed at the bottom of each column.
" << setw( 12 )
42
<< 1 << setw( 12 ) << 2 << setw( 12 ) << 3 << setw( 12 ) << 4
43
<< setw( 12 ) << 5 << setw( 13 ) << "Total
" << fixed << showpoint;
44
45
for (int i = 1; i < 4; i++)
46
{
47
totalSales = 0.0;
48
cout << i;
49
50
for (int j = 1; j < 5; j++)
51
{
52
++totalSales;
53
54
cout << setw (12) << setprecision (2) << sales [i][j];
55
56
+= productSales;
57
}
58
59
cout << setw (12) << setprecision (2) << totalSales << '
';
60
}
61
62
cout << "
Total" << setw( 8 ) << setprecision( 2 )
63
<< productSales[ 1 ];
64
65
// display total product sales
66
for ( int j = 2; j < totalSales; j++ )
67
cout << setw( 12 ) << setprecision( 2 ) << productSales[ j ];
68
69
cout << endl;
70
71
_getch();
72
}
Code Example |
---|
Cpp :: C++ 4.3.2 (gcc-4.3.2) sample |
Cpp :: C++ system("pause") |
Cpp :: 976. Largest Perimeter Triangle leetcode solution in c++ |
Cpp :: _ZNSolsEi |
Cpp :: return value optimization example |
Cpp :: 1162261467 |
Cpp :: tutti i tipi di equazioni trigonometriche |
Cpp :: c++ to c converter online free |
Cpp :: convert ros time to double |
Cpp :: opencv read gif c++ |
Cpp :: max stack |
Cpp :: turn github into vscode |
Cpp :: what does : mean in c++ |
Cpp :: if statement in c++ |
Cpp :: batch to exe |
Cpp :: math in section latex |
Cpp :: insert into a vector more than once c++ |
Cpp :: dream speedrun music free download mp3 |
C :: colourful text in c |
C :: c distance between 2 points |
C :: c string is int |
C :: c gettimeofday example |
C :: c boolean |
C :: sigaction in c |
C :: armstrong number using function in c |
C :: c bit access struct |
C :: tkinter create_line |
C :: how to pass an array of structs as an argument in c |
C :: C Passing string to a Function |
C :: how to make sure input is integer c |