-
Notifications
You must be signed in to change notification settings - Fork 14
/
2.42_1.25.cpp
41 lines (40 loc) · 1.01 KB
/
2.42_1.25.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
#include<iostream>
#include<string>
#include "Sales_data.h"
int main()
{
Sales_data total;
double price;
if(std::cin >> total.ISBN >> total.amount >> price)
{
total.totalPrice = price * total.amount;
Sales_data trans;
while (std::cin >> trans.ISBN >> trans.amount >> price)
{
trans.totalPrice = price * trans.amount;
if(total.ISBN == trans.ISBN)
{
total.amount += trans.amount;
total.totalPrice += trans.totalPrice;
}
else
{
std::cout << total.ISBN << ' ' << total.amount << ' ' << total.totalPrice;
if(total.amount > 0)
std::cout << ' ' << total.totalPrice / total.amount << std::endl;
else
std::cout << ' ' << "No Sales!" << std::endl;
total = trans;
}
}
std::cout << total.ISBN << ' ' << total.amount << ' ' << total.totalPrice;
if(total.amount > 0)
std::cout << ' ' << total.totalPrice / total.amount << std::endl;
else
std::cout << ' ' << "No Sales!" << std::endl;
} else {
std::cerr << "No data?!" << std::endl;
return -1;
}
return 0;
}