-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.22.cpp
More file actions
30 lines (24 loc) · 695 Bytes
/
1.22.cpp
File metadata and controls
30 lines (24 loc) · 695 Bytes
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
#include "Sales_data.h"
#include <iostream>
using std::cerr;
using std::cout;
using std::cin;
using std::endl;
int main() {
Sales_data total, data;
double price;
if (!(cin >> total.bookNo >> total.units_sold >> price)) {
cerr << "No data?!" << endl;
return -1;
}
total.revenue = total.units_sold * price;
while (cin >> data.bookNo >> data.units_sold >> price) {
data.revenue = data.units_sold * price;
total.bookNo = "";
total.units_sold += data.units_sold;
total.revenue += data.revenue;
}
double average_price = total.revenue / total.units_sold;
cout << total.bookNo << " " << total.units_sold << " " << total.revenue << " " << average_price << endl;
return 0;
}