diff options
author | Oskar <[email protected]> | 2024-08-03 22:51:15 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-08-03 22:51:15 +0200 |
commit | 1d105b91b9678ffaa8eddea2218ed1789f5be27c (patch) | |
tree | 89563fd6bcbe5411b244ac361098fbdddc321f5f /1p25.cpp | |
parent | 0de72ab100011ab54f99f298e936327011ebc706 (diff) |
more assignments
Diffstat (limited to '1p25.cpp')
-rw-r--r-- | 1p25.cpp | 26 |
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; +} |