i created a library managment system but it would just skip the steps and run all the way down

Advertisements

i created a library manangment system with various switch cases and loops and breaks statements however sometimes it works absolutely fie however 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 tired researching on various sites and with my collegues but no one was able to fnd the solution as we all are new to c and are in early learning phase

>Solution :

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 .

Leave a ReplyCancel reply