Let's call this a fun little game. An exercise in creativity, if you will.
I've written a very simple program that does something arbitrary (converts between Euros and US Dollars, to be precise*), and I'll post the driver here. The goal is for everyone interested to sharpen their tools and their wits to fill in the blanks and produce a working program.
The rules are simple. Don't change the driver, but come up with a program that compiles and runs.
Code:
int main() try
{
const int tries = 3;
// TODO: Not hardcode requested password
jsw::Password password ( "skip", tries );
if ( password.Get ( "Please enter your password: " ) )
{
const std::string prompt[] = { "Euros: ", "Dollars: " };
const std::string result[] = { "In Dollars: ", "In Euros: " };
enum { euro_to_dollar = 1, dollar_to_euro };
jsw::Selection menu; // Menu controller
int selector; // Menu selector
double value; // Value to convert
// Set up and process menu
menu.Add ( euro_to_dollar, "1) Euros to Dollars" );
menu.Add ( dollar_to_euro, "2) Dollars to Euros" );
selector = menu.Get ( "Selection: " );
// Set up and process conversion
std::cout<< prompt[selector - 1];
value = jsw::Input::Get<double> ( std::cin );
std::cout<< result[selector - 1];
std::cout.setf ( std::ios::fixed, std::ios::floatfield );
std::cout.precision ( 2 );
if ( selector == euro_to_dollar )
std::cout<< jsw::MonetaryConversion::EuroToDollar ( value ) <<'\n';
else
std::cout<< jsw::MonetaryConversion::DollarToEuro ( value ) <<'\n';
}
else
std::cerr<<"Too many incorrect passwords. Closing...\n";
}
catch ( const std::exception& ex ) {
std::cerr<< ex.what() <<'\n';
}
Have fun!
* Grown from improving the code from a recent post