aboutsummaryrefslogtreecommitdiff
path: root/week07/ex2.cpp
blob: 2e0d16ff9057d6d637c336879b2f99183855bde5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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;
	}
}