Char wont work

Hi. I'm not having a big problem. just curious why it wont work. It will convert yen and pounds to dollars but when i enter a number followed by the letter e for euros it wont work. if i change the program to enter say 't' for euros it will work just fine. anybody know why this is?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
inline void keep_window_open() {char ch; cin >> ch;}

//	conversion program to convert yen, euros, and pounds to dollars
int main()
{
	const double yen_per_dollar = 0.010196;	// yen per dollar
	const double euro_per_dollar = 1.3231;	// euros per dollar
	const double pound_per_dollar = 1.4247;	// pounds per dollar
	double currency = 1;
	char unit = ' ';
	cout << "Please enter number of yen(y), euros(e), or pounds(p) followed by given unit to convert to U.S. dollars: ";
	cin >> currency >> unit;
	
	if (unit == 'y')
		cout << currency << " Japanese yen = " << yen_per_dollar*currency << " U.S. dollars\n";
	else if (unit == 'e')
		cout << currency << " Euros = " << euro_per_dollar*currency << " U.S. dollars\n";
	else if (unit == 'p')
		cout << currency << " British pounds = " << pound_per_dollar*currency << " U.S. dollars\n";
	else
		cout << "Sorry, I don't know a unit you called '" << unit << "'\n";
}
I think because you can give floats in scientific notation using "e", like 5e3 would be 5 * 103, so it's getting extracted into currency
Last edited on
Topic archived. No new replies allowed.