summaryrefslogtreecommitdiff
path: root/3.1-v5.cpp
diff options
context:
space:
mode:
authorOskar <[email protected]>2024-08-03 22:51:15 +0200
committerOskar <[email protected]>2024-08-03 22:51:15 +0200
commit1d105b91b9678ffaa8eddea2218ed1789f5be27c (patch)
tree89563fd6bcbe5411b244ac361098fbdddc321f5f /3.1-v5.cpp
parent0de72ab100011ab54f99f298e936327011ebc706 (diff)
more assignments
Diffstat (limited to '3.1-v5.cpp')
-rw-r--r--3.1-v5.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/3.1-v5.cpp b/3.1-v5.cpp
new file mode 100644
index 0000000..95df66f
--- /dev/null
+++ b/3.1-v5.cpp
@@ -0,0 +1,44 @@
+#include <iostream>
+#include "sales_data.hpp"
+
+/*
+ *
+ * 2.41 - 1.25
+ *
+ *
+ */
+using std::cout;
+using std::cin;
+using std::endl;
+using std::cerr;
+int main() {
+
+ SalesData total; // variable to hold data for the next transaction
+ double price = 0.0;
+ if (cin >> total.BookNo >> total.UnitsSold >> price) {
+ total.Revenue = price * total.UnitsSold;
+ SalesData trans; // variable to hold the running sum
+ while (cin >> trans.BookNo >> trans.UnitsSold >> price) {
+ trans.Revenue = price * trans.UnitsSold; // We can either keep this line, or comment this line out and uncomment line 34. Same behavior either way, just 2 different ways of doing the same thing. Though i do think that this is the more "correct" way of doing it
+ if (total.BookNo == trans.BookNo) {
+ total.UnitsSold += trans.UnitsSold;
+ total.Revenue += trans.Revenue;
+ } else {
+ double average = total.Revenue / total.UnitsSold;
+ cout << total.BookNo << " " << total.UnitsSold << " "
+ << total.Revenue << " avg: " << average << endl;
+ total = trans;
+ //total.Revenue = price * total.UnitsSold;
+ }
+ }
+
+ double average = total.Revenue / total.UnitsSold;
+ cout << total.BookNo << " " << total.UnitsSold << " "
+ << total.Revenue << " avg: " << average << endl;
+ } else {
+ cerr << "No data?!" << endl;
+ return -1;
+ }
+
+ return 0;
+}