Value

With the function below the question is what is " value" when '/' is entered. Yes the answer is 28. But how does the program get to that. Please explain the basic calculation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;

int main() {

int value = 5;
char type;
cin >> type;
switch (type)
{
case '+': value += 5;
case '/': value = 100/value;
case '-': value = value/2;
case '%': value += value % 2 + 4;
default: value += value / 3 + 10;
}

return value;
}
closed account (z05DSL3A)
Read up on switch fallthrough.
Topic archived. No new replies allowed.