Suppose the input value for type is the character‘/’. What is the value of value after the following C++ code has been executed? (2)
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;
}
2) You have neglected to put break statements in your cases. This means that code execution will continue from one block to the next, so that all of the following lines will be executed:
7 8 9 10
value = 100/value;
value = value/2;
value += value % 2 + 4;
value += value / 3 + 10;
We often describe this as "falling through" from one case to the next.
one more help I am Biginner pls bear with me, I am struggling to understand how this arrive at 13 as an answer when u subtitute 2 for a and count will be zero if Im following well then it will return a value of 3 then do I use the 3 again which count will be1 this time
#include <iostream>
using namespace std;
int result(int valueP)
{
int count = 0;
int a = 2;
while (count < valueP)
{
a += count + a / 2;
count += 2;
}
return a;
}
int main ()
{
cout << result(6) << '\n';
return 0;
}