Here's a C++ version.
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
int main(int argc, char * argv[])
{
// configure inline arguments
if (argc != 2)
{
cout << "Enter a number followed by either a 'm' for miles\n";
cout << "or a 'k' for kilometers. Example 1000m\n";
cerr << "Usage: " << argv[0] << " number(m/k)\n";
exit(1);
}
string str(argv[1]);
float spol = 186000.00;
float spos = 774.98;
int strl = (str.size() - 1);
if (str.find("m") == strl)
{
float dist = atof(str.c_str());
cout << "Traveling @ the speed of light would take \n";
cout << dist / spol << " seconds to travel " << dist;
cout << " miles." << endl;
cout << "\nTraveling @ the speed of sound would take \n";
cout << dist / spos << " hours to travel " << dist;
cout << " miles." << endl;
}
else if (str.find("k") == strl)
{
float dist = atof(str.c_str());
cout << "\nTraveling @ the speed of light would take \n";
cout << (dist * 0.621) / spol << " seconds to travel " << dist;
cout << " kilometers." << endl;
cout << "\nTraveling @ the speed of sound would take \n";
cout << (dist * 0.621) / spos << " hours to travel " << dist;
cout << " kilometers." << endl;
}
else
cout << "\nSorry I don't understand this -> (" << str << ") input";
return 0;
}
Output
D:\>traveltime 1500m
Traveling @ the speed of light would take
0.00806452 seconds to travel 1500 miles.
Traveling @ the speed of sound would take
1.93553 hours to travel 1500 miles.