From 1d105b91b9678ffaa8eddea2218ed1789f5be27c Mon Sep 17 00:00:00 2001 From: Oskar Date: Sat, 3 Aug 2024 22:51:15 +0200 Subject: more assignments --- 1p25.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 1p25.cpp (limited to '1p25.cpp') 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 +#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; +} -- cgit v1.2.3