I'm having trouble correctly putting this function into my code.
Pausing a Command Prompt Program One of the nuisances of C++ compilers, such as our recommended DevC++ compiler, is how they handle simple "console applications". These are programs like the ones demonstrated in our textbook and like the ones we will write for homework. Console applications use the Command Prompt window to interact with the user, using textual inputs and outputs. When we compile and create a console application, the compiler creates an executable .EXE file. When we run that program, a Command Prompt window opens for the duration of the program.
And that's the problem. When the program is over, the compiler chooses to close the Command Prompt window, which is no longer needed. From out point of view, the window opens momentarily and then disappears before we can view its results. Fortunately, there are simple ways to hold the window open until we have finished reviewing it. One way is to ask the user to enter a value from the keyboard and read that value in. right at the end of the program. The window will stay visible until the user completes the input.
A better way is to use the built-in function named "system". This function can accept an argument. When that argument is the text string "Pause", the system function will pause the program and display a message to the user. The program will only continue when the user hits any key. Here is an example: #include <iostream> #include <stdlib.h> using namespace std; int main( ) { cout << "Demonstration of using System with the Pause option" << endl << endl; system("Pause"); return 0; }
This is what he said. This is what my program looks like.
http://prntscr.com/bf15o8 As you can see, I'm having trouble correctly inserting the function. The rest of the lines built and compiled well.
At line 33 you have added two endl. Try removing one.
Well, that definitely fixed one thing wrong with it. It gave me this now. error: 'system' was not declared in this scope|
@Sachintha
Have you included the library 'stdlib.h'?
Explain?
Have you included this line in you code? #include <stdlib.h>
No I have not let me try that now
That's why it didn't work. You haven't included that library.
I put it right under cout << "Your total is $" << total << endl; and then put the remaining under the library and it didn't work I'll show you how I set it up.
It should be loaded before the main() runs. Place it outside the function (in line 1 or 2).
fixed it!
Great!
Join our real-time social learning platform and learn together with your friends!