{
switch (op)
{
case 1:
case 2:
case 3:
case 4:
default: ..........................
.......................................
....................................
i have a problem , the while loop condition to stop is to enter 'q'
and inside it switch needs case 1, case 2, case 3 and case 4
so the variable should accept the integers of the cases and the 'q' to stop
First of all, your example loops as long as the provided input is NOT 'q'. Guessing from your snippet you only provide input once before you start the loop after which this never changes. So the input will never change from what you first provided. Hence the infinite loop.
when i did this , once i'm entering 1 ,2 etc it gives me a result as if it's 'default'
It will always go to the default depending on your input. In my example it WILL go to the case but since the input is followed by a '\n' (return when you press enter to submit input) it will go to the default case.
I hope this helps and there are various ways to surpas the problem I just mentioned :)
There are a few problems here.
The main one is that function int minu() asks the user for an integer, and returns an integer, therefore it isn't possible to enter an alphabetic character such as 'q'. If you do so, the statement cin >> n; at line 55 will fail. This sets the 'fail' flag for the cin stream, meaning that any subsequent operation using cin will fail, unless the error flags are cleared.
Another problem is the op = getchar(); statement at line 21. If function mine() has been successful, there will still be a newline character remaining in the input buffer. Thus, after the getchar(). op will contain '\n' and thus the switch-case will follow the "default", as '\n' was not one of the options.
I'd recommend that the function minu() should use type char instead of type int.
And I'd recommend removing the getchar() completely.