Im compiling this with visual c++ .net and when i try and end the while loop with the end of file character ( control + z ) it drops me completely out of the console window.
Code:
#include <iomanip>
#include <ios>
#include <iostream>
#include <string>
// debug
#define DEBUG
using std::cin; using std::setprecision;
using std::cout; using std::string;
using std::endl; using std::streamsize;
int main()
{
// ask for / read students name
cout << "Please enter your first name: ";
string name;
cin >> name;
cout << "Hello, " << name << "!" << endl;
// ask for / read mid term and final grades
cout << "Please enter your mid-term and final grades: ";
double mid, final;
cin >> mid >> final;
// +++++++++++++ DEBUG
#ifdef DEBUG
cout << "before while loop" << endl;
cout << "enter to confirm" << endl;
cin.ignore();
cin.get();
#endif
// ------------- eof DEBUG
// ask for homework grades
cout << "Enter all your homework grades, "
"followed by end-of-file: ";
// the number and sum of grades read so far
int count = 0;
double sum = 0.0;
// variable to temp the homework grades
double x;
// gather data
while (cin >> x)
{
++count;
sum += x;
}
// +++++++++++++ DEBUG
#ifdef DEBUG
cout << "after while loop" << endl;
cout << "enter to confirm" << endl;
cin.ignore();
cin.get();
#endif
// ------------- eof DEBUG
// write result
streamsize prec = cout.precision();
cout << "Your final grade is " << setprecision(3)
<< (0.2 * mid) + (0.4 * final) + ((0.4 * sum) / count)
<< setprecision(prec) << endl;
// pause
cin.ignore();
cin.get();
return 0;
}
I thought this was something really stupid that i was missing but i loaded this cpp file up on my laptop and compiled it with microsoft visual c++ 6 ( the version before .net ) and it worked.... when i entered the end of file character ( control + z ) it carried on with the program and printed out my results.
Any ideas how to make this work on my visual studio .net version???????
also this is all on windows xp