C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 08-01-2002, 11:23 AM   #1
Registered User
 
Join Date: Aug 2002
Posts: 2
Exclamation 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
sweetgem is offline   Reply With Quote
Old 08-01-2002, 12:03 PM   #2
Registered User
 
hk_mp5kpdw's Avatar
 
Join Date: Jan 2002
Location: Northern Virginia/Washington DC Metropolitan Area
Posts: 2,870
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.
__________________
On two occasions I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
--Charles Babbage, 1792-1871

09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
hk_mp5kpdw is online now   Reply With Quote
Old 08-01-2002, 12:41 PM   #3
Registered User
 
Join Date: Aug 2002
Posts: 2
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?
sweetgem is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Conversion Char To Char * Problem ltanusaputra Windows Programming 3 03-01-2008 02:06 PM
Simple Display Problem? portable C Programming 4 01-03-2008 06:53 AM
problem with A simple modeless messagebox hanhao C++ Programming 8 07-05-2005 11:18 PM
C / OpenGL help REALLY needed for simple but annoying problem! Oz_joker C Programming 5 12-03-2003 05:47 PM
Currency Conversion Program kgraw21 C Programming 5 04-19-2002 08:39 AM


All times are GMT -6. The time now is 05:39 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22