-
Fill in the blanks
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! :D
* Grown from improving the code from a recent post
-
Can you change the code via #defines or extra } braces? I can't see how you could get it to compile otherwise.
-
I think prelude is asking us to code what is left so that piece of code compiles and runs as expected. It's a fun little game actually :)
I can see a namespace, a user-defined object, a templated member function... etc...
It's the try-catch that beats me. I don't know how to work with that setup. But nothing like a good read to get there.
-
The try-catch would be an easy fix if you could do this:
Code:
#define try try {
// ... main() function here ...
}
-
>Can you change the code via #defines or extra } braces?
You can add anything you want above or below, but what's there is what's there. Though you may be confusing the intention of the game. This isn't one of those stupid "make it work as is" projects where you have to do silly hacks, it's more of a project where you have a limited view of the code and need to reverse engineer it. Given the driver, it's possible to reproduce the complete program that I cut it from.
>I can't see how you could get it to compile otherwise.
You can add anything you want, just don't change what I posted (directly. If you want to you can use defines, but I'll say right now that the only preprocessor usage in the original program was #include). Clearly you'll need to include some headers and write the classes that are used. ;)
>It's the try-catch that beats me. I don't know how to work with that setup.
With the exception of a handful of people on these boards, there should be some learning going on for anyone who cares to participate. This is partially a learning exercise.
-
Okay, I'll try it. I might not finish it, but you never know. It'll be at least a few days because this computer doesn't have a compiler.
-
Being 3:42 am here... i'll leave it for later :)
-
Long live Comeau Test! :) It's mildly risky because you can't run the result, but a clean compile on a conforming compiler is always a good thing...right?
-
Yeah, I don't want to risk trying it without a compiler.
-
What I meant was that you can use this to compile, but you won't be able to do runtime tests.
-
I've never heard of that before . . . interesting.
-
Ok. I will definitely do this later. I can't for the life of me understand what to do about.
std::cout<< prompt[selector - 1]
nighty night :)
-
Hey Prelude, here's another online compiler: http://dinkumware.com/exam/
No registration required.
-
>No registration required.
Nifty, I'll be taking advantage of that one too, though Comeau doesn't require registration either. I just type "asdf" in the required fields and have at it. :p
-
Yeah, me too, but even "asdf" takes longer to type than nothing. :)
Now all we need is an online code formatter . . . .