Console closing down (tried cin.get() etc...)

I'm fairly new to C++ so please bear with me. I've tried cin.get() cin.clear() etc but nothing works so far. I pressed ctrl+Z to end the while loop. Don't know if it has anything to do with it.
Thank you guys!

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
  #include <iostream>
#include <string>
#include <iomanip>
#include <ios>

using namespace std;

int main()
{
	cout<<"Please enter student's name"<<endl;
	string name;
	cin>>name;
	cout<<"Please enter your midterm and final exam grades"<<endl;
	double midterm,final;
	cin>>midterm>>final;
	cout<<"Please enter all your HW grandes below"<<endl;
	int count=0;
	double sum=0;

	double x; //a variable to read as one HW grade
	while (cin>>x)
	{
		sum=sum+x;
		count++;
		
	}

	streamsize prec=cout.precision();
	cout<<"Your final semester grade is "<<setprecision(3)<<0.2*midterm+0.4*final+0.4*sum/count<<setprecision(prec)<<endl;
	//cin.clear(); 
	//cin.sync();
	cout<<"enter any number to exit"<<endl;
	int i;
	cin>>i;
	
	return 0;

}
What do you mean? Does it not function, or do you get an error?
Sorry I didn't make my question very clear. i didn't get an error. I don't know how to prevent the console from closing down after execution. The console closes down right after I entered ctrl+Z+enter (to satisfy the 'false' condition for the while loop i think? ) so I didn't even get a chance to see if the last output is correct.
Try putting

1
2
3
4
...

system ("pause");
return 0;
I'm tempted to report this entire thread. "Console Closing Down" is literally the title of the second sticky thread on this board. It answers this exact question with discussion of methods that work and why some methods are better than others.
@ OP: When you ping a remote computer or a website, does ping.exe try to keep the console open for you so that you can read the result? How about calcs.exe? How about any of the console tools in SysInternals? Why do you think that none of these console applications bother to do what you are trying to do here? I'm being serious here.
Thank you guys. I read the thread console closing down and tried as shown in my code. But still couldn't get it work. But now it works. Thanks again.
Registered users can post here. Sign in or register to post.