If you include <cctype> library, there is a function that can convert any uppercase character to lowercase.
You can take advantage of that function. You can convert all letters in user input to lowercase and it can reduce the number of relational operations significantly.
You can use something like this...
1 2 3 4
|
cin >> answer;
for ( int iter = 0 ; iter < answer.length () ; iter ++ )
answer [iter] = tolower ( answer [iter] );
|
So if user input is "Pound", it will be changed to "pound"
If I typed something stupid like "pOuNd", it will still be converted to "pound"
After you convert a string to all lowercase you can simply do this
|
if ( answer == "pound" && answer2 == "euro" )
|
Another way to simplify this process (It could be simpler for user too) is to use integer to select the option. Like this,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
// Pseudocode
Enter the amount:
cin >> amount
Select the currency
1. Euro
2. Pound
3. Dollar
User types 1 for euro...
Currency you want to convert into
1. Euro
2. Pound
3. Dollar
User types 2 for pound
if ( answer == 1 && answer2 == 2 )
.
.
.
|
It's easier for us to just type 1 2 or 3 then typing the entire string.
It's easier for you to code the input validator for integers