summaryrefslogtreecommitdiff
path: root/1p25.cpp
diff options
context:
space:
mode:
Diffstat (limited to '1p25.cpp')
-rw-r--r--1p25.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/1p25.cpp b/1p25.cpp
new file mode 100644
index 0000000..880a94b
--- /dev/null
+++ b/1p25.cpp
@@ -0,0 +1,26 @@
+#include <iostream>
+#include "sales_item.hpp"
+int main() {
+ Sales_item total; // variable to hold data for the next transaction
+ // read the first transaction and ensure that there are data to process
+ if (std::cin >> total) {
+ Sales_item trans; // variable to hold the running sum
+ // read and process the remaining transactions
+ while (std::cin >> trans) {
+ // if we’re still processing the same book
+ if (total.isbn() == trans.isbn())
+ total += trans; // update the running total
+ else {
+ // print results for the previous book
+ std::cout << total << std::endl;
+ total = trans; // total now refers to the next book
+ }
+ }
+ std::cout << total << std::endl; // print the last transaction
+ } else {
+ // no input! warn the user
+ std::cerr << "No data?!" << std::endl;
+ return -1; // indicate failure
+ }
+ return 0;
+}