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 Bottom