forked from chihyang/CPP_Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExer02_41_2.cpp
More file actions
26 lines (26 loc) · 766 Bytes
/
Copy pathExer02_41_2.cpp
File metadata and controls
26 lines (26 loc) · 766 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
// Rewrite of Exer1.21
#include<iostream>
struct Sales_data {
std::string bookNo;
unsigned units_sold = 0;
double revenue = 0.0;
};
int main()
{
Sales_data book1, book2;
double price1 = 0, price2 = 0;
std::cin >> book1.bookNo >> book1.units_sold >> price1;
std::cin >> book1.bookNo >> book1.units_sold >> price2;
book1.revenue = price1 * book1.units_sold;
book2.revenue = price2 * book2.units_sold;
if(book1.bookNo == book2.bookNo)
std::cout << book1.bookNo << " "
<< book1.units_sold + book2.units_sold << " "
<< book1.revenue + book2.revenue << std::endl;
else
{
std::cerr << "Two items have different isbn!" << std::endl;
return -1;
}
return 0;
}