Apr 18, 2013 at 3:22am UTC
While the program is processing I am wondering if there is a way to display a message that says system processing?
#include<cmath>
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main ()
{
double d, d2, y, r, x, x2, y2, z2,x1, y1, z1, NOL1, NOL2, dump;
string filename1, filename2;
ifstream zone1, zone2;
cout << "Enter name of input file:";
cin >> filename1;
zone1.open(filename1.c_str());
cout << "Enter name of input file:";
cin >> filename2;
zone2.open(filename2.c_str());
if(zone1.fail())
{
cerr << "Error opening input files\n";
exit(1);
}
if(zone2.fail())
{
cerr << "Error opening input files\n";
exit(1);
}
zone1 >> NOL1;
zone2 >> NOL2;
d2 = 999999999; //double d_2 =MaxVal(99999999)(DBL_MAX);
for(int i = 1; i <= NOL1; i++)
{
zone1 >> x1 >> y1 >> z1;
for(int j = 1; j <= NOL2; j++)
{
zone2 >> x2 >> y2 >> z2;
d = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2) + pow(z2 - z1, 2));
if (d < d2)
{
d2 = d;
}
}
zone2.close();
zone2.open(filename2.c_str());
zone2 >> dump;
}
zone1.close();
zone2.close();
cout << "The shortest distance is: " << d2 << endl;
system("pause");
return 0;
}
Apr 18, 2013 at 6:01am UTC
just before the processing starts, you can print a message ? Or do you want something else ?
always put code between code tags. see right side format panel.
Apr 19, 2013 at 3:18am UTC
While the program is going through the iterations of the loop instead of just pausing I would like it to print something like system processing, wondering how to do that?
Apr 19, 2013 at 4:10am UTC
If you can calculate the percentage of processing done, you can print that in the loop.
Otherwise, you can print a 'spinner', overwriting the characters \ | / - in order.
Use cout << "\r" << percent_done << "%" << flush;
to do it.
You might also want to consider a timer, so you only output something after a reasonable amount of time has passed, instead of too quickly.
Hope this helps.