abracadabra1
Diamond Member
Having trouble getting this C++ program to run properly. If anyone has any advice I would appreciate it greatly.
Here's the assignment:
1. Write a program that converts between Dollars, Euros and Pounds. The program reads input from the user in the following format: Convert amount currency_1 to currency_2 and prints results in the obvious way. Here are a couple of sample runs:
Command: Convert 3.50 Euros to Dollars
Results: 3.43679
Command: Convert 3.50 Euros to Pounds
Results: 2.21707
2. Here are the conversion rates you'll need: 1.00 Dollar is 1.01838 Euros and 1.00 Dollar is 0.64510 Pounds.
3. Extend your program from Part 1 to allow for Canadian dollars as well (1.00 Dollar US is 1.55870 Dollars Canadian). Now the user can't simply put "Dollar" in the input, it must be either "Dollar US" or "Dollar Canadian". Here are a couple of sample runs:
Command: Convert 3.50 Euros to Dollars US
Results: 3.43679
Command: Convert 11.72 Dollars US to Dollars Canadian
Results: 18.26796
Turn-in: Source code and a screen shot of your program executing the four sample commands listed above.
here's the code:
------------------------------------------------------------------------------------------------------------------------------------------------
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
float amnt;
double currency;
string bogus1, bogus2, mon1, mon2, mon3;
const double USeu = 1.01838, USuk = 0.64510, UScd = 1.55870;
int main ()
{
if (cin >> bogus1 >> amnt >> mon1 >> bogus2 >> mon2)
{
if (mon1 == "Euros" && mon2 == "Dollars")
{
currency = amnt / USeu;
}
else if (mon1 == "Euros" && mon2 == "Pounds")
{
currency = amnt * (USuk/USeu);
}
else if (mon1 == "Dollars" && mon2 == "Euros")
{
currency = amnt * USeu;
}
else if (mon1 == "Dollars" && mon2 == "Pounds")
{
currency = amnt * USuk;
}
else if (mon1 == "Pounds" && mon2 == "Dollars")
{
currency = amnt / USuk;
}else if (mon1 == "Pounds" && mon2 == "Euros")
{
currency = amnt / USuk * USeu;
}
}
else if (cin >> bogus1 >> amnt >> mon1 >> bogus2 >> mon2 >> mon3)
{
if (mon1 == "Euros" && mon2 == "Dollars" && mon3 == "Canadian")
{
currency = amnt * UScd/USeu;
}
else if (mon1 == "Euros" && mon2 == "Dollars" && mon3 == "US")
{
currency = amnt / USeu;
}
else if (mon1 == "Dollars" && bogus2 == "US" && mon3 == "Euros")
{
currency = amnt * USeu;
}
else if (mon1 == "Dollars" && bogus2 == "Canadian" && mon3 == "Euros")
{
currency = amnt / UScd * USeu;
}
else if (mon1 == "Dollars" && bogus2 == "US" && mon3 == "Pounds")
{
currency = amnt * USuk;
}
else if (mon1 == "Dollars" && bogus2 == "Canadian" && mon3 == "Pounds")
{
currency = amnt / UScd * USuk;
}
}
cout << "Result: " << currency << endl;
return 0;
}
/*
Command: Convert 3.50 Euros to Dollars US
Results: 3.43679
Command: Convert 11.72 Dollars US to Dollars Canadian
Results: 18.26796
/*Convert 3.50 Euros to Pounds
1.00 Dollar is 1.01838 Euros
1.00 Dollar is 0.64510 Pounds
1.00 Dollar US is 1.55870 Dollars Canadian
*/
Here's the assignment:
1. Write a program that converts between Dollars, Euros and Pounds. The program reads input from the user in the following format: Convert amount currency_1 to currency_2 and prints results in the obvious way. Here are a couple of sample runs:
Command: Convert 3.50 Euros to Dollars
Results: 3.43679
Command: Convert 3.50 Euros to Pounds
Results: 2.21707
2. Here are the conversion rates you'll need: 1.00 Dollar is 1.01838 Euros and 1.00 Dollar is 0.64510 Pounds.
3. Extend your program from Part 1 to allow for Canadian dollars as well (1.00 Dollar US is 1.55870 Dollars Canadian). Now the user can't simply put "Dollar" in the input, it must be either "Dollar US" or "Dollar Canadian". Here are a couple of sample runs:
Command: Convert 3.50 Euros to Dollars US
Results: 3.43679
Command: Convert 11.72 Dollars US to Dollars Canadian
Results: 18.26796
Turn-in: Source code and a screen shot of your program executing the four sample commands listed above.
here's the code:
------------------------------------------------------------------------------------------------------------------------------------------------
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
float amnt;
double currency;
string bogus1, bogus2, mon1, mon2, mon3;
const double USeu = 1.01838, USuk = 0.64510, UScd = 1.55870;
int main ()
{
if (cin >> bogus1 >> amnt >> mon1 >> bogus2 >> mon2)
{
if (mon1 == "Euros" && mon2 == "Dollars")
{
currency = amnt / USeu;
}
else if (mon1 == "Euros" && mon2 == "Pounds")
{
currency = amnt * (USuk/USeu);
}
else if (mon1 == "Dollars" && mon2 == "Euros")
{
currency = amnt * USeu;
}
else if (mon1 == "Dollars" && mon2 == "Pounds")
{
currency = amnt * USuk;
}
else if (mon1 == "Pounds" && mon2 == "Dollars")
{
currency = amnt / USuk;
}else if (mon1 == "Pounds" && mon2 == "Euros")
{
currency = amnt / USuk * USeu;
}
}
else if (cin >> bogus1 >> amnt >> mon1 >> bogus2 >> mon2 >> mon3)
{
if (mon1 == "Euros" && mon2 == "Dollars" && mon3 == "Canadian")
{
currency = amnt * UScd/USeu;
}
else if (mon1 == "Euros" && mon2 == "Dollars" && mon3 == "US")
{
currency = amnt / USeu;
}
else if (mon1 == "Dollars" && bogus2 == "US" && mon3 == "Euros")
{
currency = amnt * USeu;
}
else if (mon1 == "Dollars" && bogus2 == "Canadian" && mon3 == "Euros")
{
currency = amnt / UScd * USeu;
}
else if (mon1 == "Dollars" && bogus2 == "US" && mon3 == "Pounds")
{
currency = amnt * USuk;
}
else if (mon1 == "Dollars" && bogus2 == "Canadian" && mon3 == "Pounds")
{
currency = amnt / UScd * USuk;
}
}
cout << "Result: " << currency << endl;
return 0;
}
/*
Command: Convert 3.50 Euros to Dollars US
Results: 3.43679
Command: Convert 11.72 Dollars US to Dollars Canadian
Results: 18.26796
/*Convert 3.50 Euros to Pounds
1.00 Dollar is 1.01838 Euros
1.00 Dollar is 0.64510 Pounds
1.00 Dollar US is 1.55870 Dollars Canadian
*/