0

I am currently trying to learn C++ and I have written the following program. It does what it should successfully, however it keeps auto exiting. I have tried putting a cin at the end and when that didn't work I put a getChar() and it doesn't wait for any input. To be clear, I have had no formal education regarding C++ and this problem has had me stumped. I have tried googling it but all that comes up is it telling me to use either of the things I have already tried. I have commented out the cin breakpoints to show where I put them.

As I said earlier, the actual code for the program is below. Underneath that is the debug log.

For what it's worth, I used Visual Studio to make this.

Edit: This isn't a duplicate question as I want to be able to go the actual executable, double click it and get it to wait for me to press a key until it exits. With this program even if I go to the actual executable, it still auto exits.

Code

Code for the program:

#include <iostream>
#include <string>
using namespace std;

// Declare variables for intro
string intro = "Please enter your score.\n";
string prompt = ">>> ";
string nl = "\n";

// Declare grade calculation variables
int initial_grade = 0;
bool temp;

// Declare variables for perfection test
string perfect_score = "You scored perfectly, congratulations!\n";

void perfection_test() {
    switch (initial_grade) {
    case 100:
        cout << perfect_score;
        //cin;
    }
    //cin;

}

int main() {
    cout << intro << prompt;
    cin >> initial_grade;
    cout << nl;

    //cin;
    perfection_test();
    //cin;
}

Debug:

'GradingProgram.exe' (Win32): Loaded 'C:\Users\student\Desktop\khush\GradingProgram\Debug\GradingProgram.exe'. Symbols loaded.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ntdll.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel32.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\KernelBase.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\vcruntime140d.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcp140d.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\ucrtbased.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msvcrt.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll'. Cannot find or open the PDB file.
'GradingProgram.exe' (Win32): Loaded 'C:\Windows\SysWOW64\kernel.appcore.dll'. Cannot find or open the PDB file.
The thread 0x134c has exited with code 0 (0x0).
The thread 0x2110 has exited with code 0 (0x0).
The thread 0x210c has exited with code 0 (0x0).
The program '[9092] GradingProgram.exe' has exited with code 0 (0x0).
Koga
  • 523
  • 4
  • 13
  • FWIW the `cin` trick is `cin.get();` not just `cin;`. `cin;` is a non-op – NathanOliver Jul 19 '16 at 14:11
  • Then it is a dupe of [this](http://stackoverflow.com/questions/24776262/pause-console-in-c-program). – NathanOliver Jul 19 '16 at 14:15
  • @NathanOliver doing the Start without Debugging trick worked out, however `cin.get()` doesn't work either. It just skips over it unless I put it into a variable. Is this the expected behaviour? – Koga Jul 19 '16 at 14:16
  • You generally have to do `cin.get()` after every input operation if you really want to be sure it will work or you can also call `std::cin.ignore(std::numeric_limits::max(), '\n');` before the last one as well to clear the buffer. – NathanOliver Jul 19 '16 at 14:19

0 Answers0