| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I just started learning C++ and I'm writing a simple program for class. We were supposed to write a C++ program that displays a title, "Currency Conversion" and then writes the names of five currencies and their equivalents to a US Dollar. The conversions are hard-coded equations. I had no problem with this, but then my instructor wanted the class to expand the "Currency Conversion" program to accept as input, one currency that is error checked as a valid entry and then display its equivalency in US Dollars. That's where I had problems. Below is what I have, please keep it basic, and any help is appreciated. Right now all I get is the countries listed, and when you pick a country and press enter the program closes instead of showing the conversion for that country.......
Thanks #include <iostream> //include code from the file iostream #include <fstream.h> // file I/O #include <iomanip.h> // format manipulation using namespace std; int main() { int numinput; int countrynum; cout << "***** Money Conversion *****\n\n"; cout << "1. Japanese Yen\n"; cout << "2. Euro\n"; cout << "3. Swiss Franc\n"; cout << "4. Canadian Dollar\n"; cout << "5. British Pounds\n\n\n"; cout << "Choose a number from 1 to 5 for that country's conversion" << endl; cin >> numinput; cin >> countrynum cin>> countrynum = 1 cout << numinput*111.7850 << endl; if countrynum = 2 cout << numinput*0.8371 << endl; if countrynum = 3 cout << numinput*1.2975 << endl; if countrynum = 4 cout << numinput*1.2422 << endl; if countrynum = 5 cout << numinput*0.5659 << endl; cin.get(); return 0; } |
|
#2
|
|||
|
|||
|
" I had no problem with this, but then my instructor wanted the class to expand the "Currency Conversion" program to accept as input, one currency that is error checked as a valid entry"
Can you explain what you mean by an input and what the error checking concerns? |
|
#3
|
|||
|
|||
|
Quote:
Actually, I' really not that concerned withe the error checking right now. What I want should happen is when you enter the number of one of the countries you should get the currency conversion for that country ie....... 1 Japanese Yen = 111.7850 U.S Dollar 1 Euro = 0.8371 U.S Dollar 1 Swiss Franc = 1.2975 U.S Dollar 1 Canadian Dollar = 1.2422 U.S Dollar 1 British Pound = 0.5659 U.S Dollar right now when you compile and run this it closes when you pick a country number and hit enter........... |
|
#4
|
|||
|
|||
|
change
"cin >> countrynum cin>> countrynum = 1" to "cin >> countrynum;" Prompt the user for the country first. Do you know case statements? I prefer it to a bunch of nested if statements. |
|
#5
|
|||
|
|||
|
I think ur instructor means you to write the menu driven program which means that if user enters 6(ur option is from 1 to 5) then u have to tell the user this is invalid choice and for currency if user enter any invalid symbols like letters and otehr symbols then u must check for that also, and i think u can do it with ascii codes.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Can someone help?? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|