Archived

This topic is now archived and is closed to further replies.

keeping window open from accelerated c++

This topic is 4982 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am working through an example from accelerated c++ and was wondering if anybody knows how to keep the window from closing once an end of file is read. I tried adding a cin call at the end but that does not work. #include <algorithm> #include <iomanip> #include <ios> #include <iostream> #include <string> #include <vector> using std::cin; using std::sort; using std::cout; using std::streamsize; using std::endl; using std::string; using std::setprecision; using std::vector; int main() { // ask for and read the student''s name cout << "Please enter your first name: "; string name; cin >> name; cout << "Hello, " << name << "!" << endl; // ask for and read the homework grades cout << "Enter all your homework grades, " "followed by end-of-file: "; vector homework; double x; // invariant: `homework'' contains all the homework grades read so far while (cin >> x) homework.push_back(x); // check that the student entered some homework grades typedef vector::size_type vec_sz; vec_sz size = homework.size(); if (size == 0) { cout << endl << "You must enter your grades. " "Please try again." << endl; return 1; } // sort the grades sort(homework.begin(), homework.end()); // compute the median homework grade vec_sz quarter = size/4; double median; median = size % 4 == 0 ? (homework[quarter] + homework[quarter-1]) / 2 : homework[quarter]; for( unsigned int i=0; i < size ; i++) { if(homework >= homework[quarter]) cout << homework[i] << endl; } cout << median; int j; cin >> j; return 0; }

Share this post


Link to post
Share on other sites
there are various methods, but when I studied out of that book I used a getchar() call right before return 0. Others may suggest using system("pause"); as well. Others like the mod Oluysei might start whining about either method being non-standard, but who cares for something trivial like this, right?

Share this post


Link to post
Share on other sites
you don''t need that system pause or whatever, all you have to do is go to start>run then type "cmd" a dos like window will come up. then find your executable in my computer and drag it onto the cmd screen, then hit enter and it wont disapear.

when youre done type exit in the window.

Share this post


Link to post
Share on other sites