Modify the program to find the satellite that is farthest from the receiver (rgh
ID: 3551272 • Letter: M
Question
Modify the program to find the satellite that is farthest from the receiver (rght now it finds the one that is closest)
ORIGINAL:
#include <iostream>
#include <cfloat>
using namespace std;
int main()
{
const double C(299792458.0);
const int NUMBER_OF_SATELLITES (5);
int satID, minID;
double tTime, pRange, minPRange (DBL_MAX);
cout << "Enter id and transit time for "
<< NUMBER_OF_SATELLITES << " satellites: "
<< "Use whitespace to separate the values(ie: 25 0.00257) "
<< endl;
for(int i=1; i<=NUMBER_OF_SATELLITES; ++i)
{
cin >> satID >> tTime;
pRange = tTime*C;
if(pRange < minPRange)
{
minPRange = pRange;
minID = satID;
}
cout << "Satellite " << satID << " has a pseudorange of "
<< pRange << " m n" << endl;
}
cout << " Satellite " << minID
<< " is closest to GPS receiver." << endl;
return 0;
}
?
Explanation / Answer
#include <iostream>
#include <cfloat>
using namespace std;
int main()
{
const double C(299792458.0);
const int NUMBER_OF_SATELLITES (5);
int satID, minID;
double tTime, pRange, minPRange (DBL_MAX);
cout << "Enter id and transit time for "
<< NUMBER_OF_SATELLITES << " satellites: "
<< "Use whitespace to separate the values(ie: 25 0.00257) "
<< endl;
for(int i=1; i<=NUMBER_OF_SATELLITES; ++i)
{
cin >> satID >> tTime;
pRange = tTime*C;
if(pRange > minPRange)
{
minPRange = pRange;
minID = satID;
}
cout << "Satellite " << satID << " has a pseudorange of "
<< pRange << " m n" << endl;
}
cout << " Satellite " << minID
<< " is closest to GPS receiver." << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.