# Thread: simple currency conversion problem

1. ## simple currency conversion problem

I am doing a program that is to expand the "Currency Conversion" program to accept a currency amount for one currency from the user, which is error checked as a valid entry, and then display its equivalency in US dollars. Insert comments in the program to document the program internally. Be sure not to over design the program, in particular include requirements to be added to the program in the subsequent weeks. The thing is when I do this from what i've wrote then it gives me a bad input error at the line to enter today's exchange rate. I know that it should be a string and not long but i'm not really sure how to change that. Can anyone tell this woman who's been up for 72 hours straight trying to figure it out where the heck the snake is that should've already bitten her? Any help is greatly appreciated!!

#include <iostream.h>
#include <string>
using namespace std;

int main ()
{
//enter input items
long currency = 0.0;
cout << "Enter Currency: ";
cin >> currency;
switch (currency)
{
case 'Euro':
case 'euro': cout << "Euro" << endl;
break;
case 'FF':
case 'ff': cout << "FF" << endl;
break;
case 'DM':
case 'dm': cout << "DM" << endl;
break;
case 'GBP':
case 'gbp': cout << "GBP" << endl;
break;
case 'Yen':
case 'yen': cout << "Yen" << endl;
break;

} //end switch
cout << "Enter Today's Exchange Rate:";
cin. >> currency;
if (cin.fail())
{ cout << "Error: bad input";
return 1;
}//validation of input

float rate = 0.0;
bool more = true;
cout << "Enter USD amount:"<<"\n";
while (more)

{
float usDollar = 0.0;
if (cin >> usDollar)
{
if (usDollar <= 0)//test for sentinel
more = false;
else
{
currency = usDollar * (cin, currency);
cout << currency << "";
}
}
}
return 0;
} //end of main function

2. After just a quick look:

1) It appears you are using a long data type variable to store the currency type, this should probably be a string type instead.
2) You can't use non-integral data types in your switch statement. This means no case 'DM'. If you make the above change I suggested, then this whole switch statement should be made into a if, else-if type of statement.
3) This may be a typo, but in your code there is a cin. piece where the period should not be there.
4) You should be using the <iostream> header instead of the one you have with the .h extension. The using namespace std; line takes care of any namespace problems and using this new header will match better with the <string> header you are including.

3. You were right the . was a typo...as for the long to switch i'm not sure how to go about changing that...and i got rid of the .h that's the way i had it in the beginning...should have stuck with my first instinct...any suggestions on the long to switch conversion?

Popular pages Recent additions