Read the sticky, console still closing right away

Okay, I have Windows 10. I am using Sublime Text2 with the MinGW compiler.

I went through the sticky on Console Closing down. I tried several different options, however the console still immediately closes down. I have come to the conclusion that based on the fact the post is seven years old those solutions wont work on windows 10. OR and MORE LIKELY My newness is showing and I am not putting those solutions in the correct place in my code. I pasted my code below, If one of you lovely folks could help me out I would really appreciate it. I am only on my second c++ tutorial ever. Thanks!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  //Vic R

#include <iostream>
using namespace std;




  



int main()
{
	char choice;
	cout << "a. Small Dog" << endl;
	cout << "b. Large Dog" << endl;
	cout << "c. Squid" << endl;
	cout << "Please enter menu letter for your animal: " << endl;
	cin >> choice;
	choice = tolower(choice);
	switch (choice)
	{
	case 'a':
		cout << "cost: $50.00" << endl;
		break;
	case 'b':
		cout << "cost: $25.00" << endl;
		break;
	case 'c':
		cout << "cost: $1.50" << endl;
		break;
	default: 
		cout << "invalid response" << endl;
		break;


       }




  
	
}
  
Last edited on
I've been where you are, it was pretty annoying. When I was practising coding, I just put

system("PAUSE"); at the end of the program, which is fine if you're just learning, try that.
Last edited on
gave it a shot, no luck. also in the article(s) with other options that are more complex, I get confused as to where to put the code within my code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  //Vic R

#include <iostream>
using namespace std;




  



int main()
{
	char choice;
	cout << "a. Small Dog" << endl;
	cout << "b. Large Dog" << endl;
	cout << "c. Squid" << endl;
	cout << "Please enter menu letter for your animal: " << endl;
	cin >> choice;
	choice = tolower(choice);
	switch (choice)
	{
	case 'a':
		cout << "cost: $50.00" << endl;
		break;
	case 'b':
		cout << "cost: $25.00" << endl;
		break;
	case 'c':
		cout << "cost: $1.50" << endl;
		break;
	default: 
		cout << "invalid response" << endl;
		break;


       }

system("PAUSE");


  
	
}
  
It's probably because you're using Sublime Text2. Doesnt it work if you just simply put a

1
2
int x;
cin >> x;


at the end? It has to wait for an input right? Then it can exit.
That did the trick! and what a trick it is. I'm guessing its leaving the program unfinished. of course the user has no idea to enter an input to exit, but for my purposes of learning, its perfect! Thanks dude!

I will leave this code below in case any other novice's may need it. using the code below will still keep the window open, but will prompt/instruct user how to close it.

1
2
3
int x;
cout << "Press letter then ENTER to close" << endl;
cin >> x;


Last edited on
Topic archived. No new replies allowed.