-2

I created a library manangment system with various switch cases and loops and breaks statements, however, sometimes, it works absolutely fine, but sometimes it runs the commands and follows all the statement after that particular switch statement.
My code is as undergiven: https://onlinegdb.com/aYdKFJSTy

I tried researching on various sites and with my collegues but no one was able to find the solution as we all are new to C and are in early learning phase.

EnderMega
  • 79
  • 10
  • 5
    Have you tried running your code line-by-line in a debugger while monitoring the control flow and the values of all variables, in order to determine in which line your program stops behaving as intended? If you did not try this, then you may want to read this: [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/q/25385173/12149471) You may also want to read this: [How to debug small programs?](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) – Andreas Wenzel Mar 05 '23 at 04:38
  • 2
    Even if using a debugger does not actually solve the problem, it should at least help you to isolate the problem and to create a [mre] of the problem, so that it will be easier for other people to help you. Most people will not be willing to debug your whole program for you, [as that should be your job](https://idownvotedbecau.se/nodebugging/). – Andreas Wenzel Mar 05 '23 at 04:43

1 Answers1

3

ok so firstly, you should stop posting a complete 900 lines of code and just give a snippet code of the part which you think is giving problem. Secondly, the places in where you are facing problem, you have missed the break statement at several places in the switch cases. When you do not put break statement in a switch case the case is executed and then all the cases after it are executed sequentially . you can either use break / exit/ continue statements depending upon your requirement. For example the switch case in the 687th line of your code does not contain any break statement. Hence, all the statements after the case chosen will be executed and an undesirable output will be displayed .

nischal sharma
  • 479
  • 1
  • 14