+ 2

How to make the console not turn off immeidately

I made a simple calculator and then compiled it.When i open the exe file.It closes immeidately after displaying the result.Is there a way to pause it after it displays the result?

11th Mar 2017, 9:40 PM
Barış
5 ответов
+ 1
Pretty simple, put the following at the end of your c++ code: std::getchar(); Since the console awayts a character, the console wont close until you're pressing any key. Oh and don't forget to #include <cstdio>
11th Mar 2017, 9:52 PM
Hoargarth
Hoargarth - avatar
+ 1
Umm maybe put... return 0; at the end of the program?
12th Mar 2017, 12:12 AM
Someone
0
if visual studio press CTRL+F5
11th Mar 2017, 10:47 PM
kibbekPL
kibbekPL - avatar
0
simple, if for simple use, put the code in an infinite loop, since it will always be true it will continue afterwards
12th Mar 2017, 12:34 AM
William La Flamme
William La Flamme - avatar
0
Try "getchar", it will hold the console screen until next key stroke. else you can put the calculator code in a loop where in the end users are supposed to choose if they want to quit or calculate more. All the best.
16th Mar 2017, 2:47 PM
Pulkit Happy
Pulkit Happy - avatar