Author Topic: EOF command for Codeblocks version 12.11 ?  (Read 9448 times)

Offline asdf__123

  • Single posting newcomer
  • *
  • Posts: 3
EOF command for Codeblocks version 12.11 ?
« on: June 09, 2014, 02:35:34 am »
I have this code and can't kick out of the while with ctrl+Z(it just prints ctrl+Z in my console window.  Any ideas ?
#include <iomanip>
#include <ios>
#include <iostream>
#include <string>

using std::cin;     using std::setprecision;
using std::cout;    using std::string;
using std::endl;    using std::streamsize;

int main()
{
    cout << "Please enter your first name: ";
    string name;
    cin >> name;
    cout << "Hello, " << name << "!" << endl;

    // ask for and read the midterm and final grades
    cout << "Please enter your midterm and final exam grades: ";
    double midterm, finalexam;
    cin >> midterm >> finalexam;

    // ask for the homework grades
    cout << "Enter all your homework grades, "
            "followed by end-of-file: ";

    // the number and sum of grades read so far
    int number = 0;
    double sum = 0;

    // a variable into which to read
    double x;

    // invariant:
    //   we have read count grades so far, and
    //   sum is the sum of the first count grades
    while (cin >> x) {
        ++number;
        sum += x;
    }

    //write the result
    streamsize prec = cout.precision();
    cout << "Your final grade is " << setprecision(3)
         << 0.2 * midterm + 0.4 * finalexam + 0.4 * sum / number
         << setprecision(prec) << endl;

    return 0;
}

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: EOF command for Codeblocks version 12.11 ?
« Reply #1 on: June 09, 2014, 03:12:07 am »
EOF is a Operating System issues.
IIRC, CNTRL Z in windows, CNTRL D in Linux.

I see no place you test for EOF in the code; but, I am NOT a C++ person.

Tim S.
« Last Edit: June 09, 2014, 03:54:31 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline asdf__123

  • Single posting newcomer
  • *
  • Posts: 3
Re: EOF command for Codeblocks version 12.11 ?
« Reply #2 on: June 09, 2014, 05:21:46 am »
Interesting, I took the code straight from the book Accelerated C++.  Will post my solution( have a feeling this will occur again later in the book) once I find it.

Offline asdf__123

  • Single posting newcomer
  • *
  • Posts: 3
Re: EOF command for Codeblocks version 12.11 ?
« Reply #3 on: June 09, 2014, 05:27:53 am »
SOLVED:  After you press ctrl+Z, you have to press enter. 
I am using Windows 7