I'd like to ask for your help. I am a begginer in C++ and I just wrote a calculator, but as soon as I choose an option, the console immediately closes.
hello.y read and run you're code..it is perfect. no errors and it works just fine,maybe the problem is somewhere else.try to put a #include <stdlib.h> and just before the return 0; put system("pause"); this will stop the program when it finishes and let's u see the console with the final result .then you press any key and then it closes.
duoas,y read about the danger of using it,and y did not really understand all but y don't say you're wrong..but for us ppl,that try to make small programs,exercises from a book,or just trying to learn c++ y will say it is ok..but if you write serious programs,and stuff like that,for different people,it maybe a serious problem.
An alternative to system("pause"); ,that y use is to simply write getchar(); in the place of it.and you can put a nice message before it so it loks fineprintf("Press Enter to continue");.this will wait for you to press enter and then the console will exit.and you don't need the stdlib library any more..is that wrong to?
No, even stupid programs should not have dangerous code in it -- right from the start. If you learn to do things the right way to begin with, you will never have to struggle to rid yourself of bad habits, and you'll never be fired or prosecuted for them.
User input code must be robust. Using getchar(); works, but for the wrong reasons. Better to use cin.ignore( numeric_limits <streamsize> ::max(), '\n' );.
All but the most trivial C++ programs are linked to the stdlib, whether or not you explicitly use it.
ok.. y now that bad habits are not good..to be honest y have no clue what that piece of code is,or what it does.maybe because y don't have the knowledge you have...but if you say it is the best way,y will use it..tnx