forked from huangmingchuan/Cpp_Primer_Answers
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexercise_3_1_b.cpp
42 lines (33 loc) · 936 Bytes
/
exercise_3_1_b.cpp
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
#include <iostream>
#include <string>
#include "exercise2_42.h"
using std::cin;
using std::cout;
using std::endl;
using std::cerr;
int main()
{
Sales_data data1, data2;
double price = 0;
cin >> data1.bookNo >> data1.units_sold >> price;
data1.revenue = data1.units_sold * price;
cin >> data2.bookNo >> data2.units_sold >> price;
data2.revenue = data2.units_sold * price;
if (data1.bookNo == data2.bookNo)
{
unsigned totalCnt = data1.units_sold + data2.units_sold;
double totalRevenue = data1.revenue + data2.revenue;
cout << data1.bookNo << " " << totalCnt
<< " " << totalRevenue << " ";
if (totalCnt != 0)
cout << totalRevenue / totalCnt << endl;
else
cout << "(no sales)" << endl;
return 0;
}
else
{
cerr << "Data must refer to the same ISBN" << endl;
return -1;
}
}