forked from chihyang/CPP_Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExer02_41_3.cpp
More file actions
32 lines (32 loc) · 892 Bytes
/
Copy pathExer02_41_3.cpp
File metadata and controls
32 lines (32 loc) · 892 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
31
32
// Rewrite of Exer1.22
#include <iostream>
struct Sales_data {
std::string bookNo;
unsigned units_sold = 0;
double revenue = 0.0;
};
int main()
{
Sales_data book, total;
double price = 0;
if(std::cin >> total.bookNo >> total.units_sold >> price)
{
total.revenue = price * total.units_sold;
while(std::cin >> book.bookNo >> book.units_sold >> price){
book.revenue = price * book.units_sold;
if(book.bookNo == total.bookNo)
{
total.units_sold += book.units_sold;
total.revenue += book.revenue;
}
else{
std::cerr << "Not the same book!" << std::endl;
break;
}
}
}
std::cout << total.bookNo << " "
<< total.units_sold << " "
<< total.revenue << std::endl;
return 0;
}