aboutsummaryrefslogtreecommitdiff
path: root/week07/ex2.cpp
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2023-12-03 15:28:54 +0200
committerSyndamia <kamen@syndamia.com>2023-12-03 15:28:54 +0200
commitb7f2b4797f8578bc23141399cfd93d4f22fbc206 (patch)
treea5bcf4cded17b7e4056a66d1534df2464065de1a /week07/ex2.cpp
parent0996e05988b5d38faba0f616f06e6dcc7466930e (diff)
downloadupp-2023-solutions-b7f2b4797f8578bc23141399cfd93d4f22fbc206.tar
upp-2023-solutions-b7f2b4797f8578bc23141399cfd93d4f22fbc206.tar.gz
upp-2023-solutions-b7f2b4797f8578bc23141399cfd93d4f22fbc206.zip
[w7] Solved simpler exercises
Diffstat (limited to 'week07/ex2.cpp')
-rw-r--r--week07/ex2.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/week07/ex2.cpp b/week07/ex2.cpp
new file mode 100644
index 0000000..2e0d16f
--- /dev/null
+++ b/week07/ex2.cpp
@@ -0,0 +1,27 @@
+#include <iostream>
+
+void sell(unsigned int& stock) {
+ stock--;
+}
+
+void receive(unsigned int& stock) {
+ stock += 10;
+}
+
+int main() {
+ unsigned int stockA = 0, stockB = 0, stockC = 0;
+ unsigned int* current = &stockA;
+
+ char buf;
+ std::cin >> buf;
+ while (buf != '$') {
+ switch(buf) {
+ case 'a': current = &stockA; break;
+ case 'b': current = &stockB; break;
+ case 'c': current = &stockC; break;
+ case 'S': sell(*current); break;
+ case 'R': receive(*current); break;
+ }
+ std::cin >> buf;
+ }
+}