From 1d105b91b9678ffaa8eddea2218ed1789f5be27c Mon Sep 17 00:00:00 2001 From: Oskar Date: Sat, 3 Aug 2024 22:51:15 +0200 Subject: more assignments --- 3.1-v3-2.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 3.1-v3-2.cpp (limited to '3.1-v3-2.cpp') diff --git a/3.1-v3-2.cpp b/3.1-v3-2.cpp new file mode 100644 index 0000000..9da81db --- /dev/null +++ b/3.1-v3-2.cpp @@ -0,0 +1,42 @@ +#include +#include "sales_data.hpp" + +/* + * + * 2.41 - 1.22 + * version 2, a bit more interactive but might not be desirable if using file redirections + * + */ +using std::cout; +using std::cin; +using std::endl; +int main () { + + SalesData book1; + SalesData Sum; + if(cin >> Sum.BookNo >> Sum.UnitsSold >> Sum.Revenue) { + while(cin >> book1.BookNo >> book1.UnitsSold >> book1.Revenue) { + if(Sum.BookNo == book1.BookNo) { + Sum.UnitsSold += book1.UnitsSold; + Sum.Revenue += book1.Revenue; + } else { + cout << "These books do not have the same ISBN" << endl; + while(1) { + std::string yesno; + cout << "Do you wish to continue? Yes/No " << endl; + cin >> yesno; + if(yesno == "Yes") { + break; + } else if(yesno == "No") { + return 0; + } + } + continue; + } + } + } + + cout << Sum.BookNo << " " << Sum.UnitsSold << " " << Sum.Revenue << endl; + + return 0; +} -- cgit v1.2.3