• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

Need suggestion for a C++ question

Joined
2/26/09
Messages
76
Points
16
Part of my course project (simulate a payment system) requires me to write a C++ code to implement following:
-----------------
[FONT=Calibri, sans-serif][FONT=Consolas, monospace]Accepts a string (input), judge whether it is a valid currency amount or not.
----------

I hope you guys can give me suggestions for:
(1) What kind of possible input scenarios may happen?
(2) What kind of efficient C++ coding approach is great for solving this?

The project is due tomorrow, so your quick help is greatly appreciated.

Regards,
Derek
[/FONT]
[/FONT]
 
Accept only Numerical/Scientific values upto 2 decimal places. If it is string then reject? or do you HAVE to accept a String and reject based on that?

Then what Ilya said would be ideal. If it is not a number then reject.
 
just start by saying

bool isValid = 1;

... series of tests, set isValid to 0 if any fail ...

return isValid;

Some common test ideas, some may or may not be applicable depending on exactly what your doing. I'm also assuming you're using USD by default.

Is it numeric?
Is it positive?
Does it go to at most 2 decimal places?
 
I think I need to consider different currencies, not just USD.

Maybe I also need to set an upper limit?

Is there a STL / string function to directly convert digital number (maybe also plus decimal point) to double number?


just start by saying

bool isValid = 1;

... series of tests, set isValid to 0 if any fail ...

return isValid;

Some common test ideas, some may or may not be applicable depending on exactly what your doing. I'm also assuming you're using USD by default.

Is it numeric?
Is it positive?
Does it go to at most 2 decimal places?
 
this is very ambiguous. You will need to ask what is the format of the amount entered.

- Is this acceptable $2.20?
- Is this acceptable USD 2.20?
- Is this acceptable USD2.20?
- Is this acceptable 2.20 USD?
- Is this acceptable 2.20USD?

Now think that we you getting a the Euro symbol or the Pound symbol or the Yen symbol or some other symbol of currency, is that acceptable? Basically, do you have to deal with internationalization or not?
 
Back
Top