Display whizzing by

Hello all,

This is for a homework assignment - just can't understand why display won't pause. Searching online, saw info on std::cin.get();
Using it, but not sure why it still won't pause.

Have some programming experience but not C++.
Any help would be appreciated.

Thanks
Code follows:


#include <iostream>
#include <fstream>


using namespace std;
const int NUMROWS = 20;

bool inRange (double MyArray[NUMROWS], double inElement) {
// the following variables store
// MIN and MAX array elements
// and their indexes
double dMin = MyArray[0];
double dMax = MyArray[0];

// process array elements
// to find MIN and MAX

for (int i=1; i<NUMROWS; i++)
{
if (MyArray[i] < dMin)
{
dMin=MyArray[i];
}
if (MyArray[i] > dMax)
{
dMax=MyArray[i];
}
}

if ((inElement >= dMin) && (inElement <= dMax))
{ return true;
}
else { return false ;
}
}

int main()

{

//If "tunnel_ordered.txt" is not available,
//Exit with an error message

ifstream inputFile("tunnel_ordered.txt");
if (!inputFile)
{
// Print an error and exit
cerr << "Input file not available! Press enter to continue" << endl;
std::cin.get();

return 1;
}

int count;

double angles[NUMROWS]; //Declare array angles
double col[NUMROWS]; //Declare array col

//For count = 1 to NUMROWS,
for (count = 0; count < NUMROWS; count++)
{
inputFile >> angles[count]; //Read flight angles into angle array
inputFile >> col[count]; //Read COL into COL array
}
inputFile.close();

cout << "The entries from input file are " << endl;

for (count = 0; count < NUMROWS; count++)
cout << fixed << angles[count] << endl;


std::cin.get();
//Ask user here to enter angle
double in_angle;
cout << "Please enter the angle " << endl;
cin >> in_angle;

bool isInRange = inRange(angles, in_angle);
if (isInRange) {
// then calculateCoef(in_angle) - temporarily commented out
cout << "You entered valid angle " << in_angle << " Press return to continue" << endl;
//print in_angle and coef
}
else {
cout << "Angle you entered is invalid. Press enter to continue" << endl;
}
std::cin.get();
return 0;
}
To further clarify,

I have std::cin.get(); in 3 places. The first one does work; the output will wait until Enter is pressed, the other two places it doesn't pause. I can see it when I run it through debug.

Topic archived. No new replies allowed.