One if not doing its job

Hi guys, I am learning C++ from Stroustrup's book and there is this "try this" in chapter 4... It says to try to write a programm that can convert euros, yens or pounds in dollars... My problem is: when my input is like "23y", "3p", "23 y", "3 p" or "877 e" everything is fine but I can't understand why the output is "Incorrect input" whe I enter values like "56e"... Can you explain it to me?? ty.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int main()
{
	constexpr double euro_dollar = 1.112320;
	constexpr double yen_dollar = 0.009010;
	constexpr double pound_dollar = 1.461730;
	double money = 1.0;
	char coin = '?';
	cout << "Enter a value and the local money you are using (e, y, p): ";
	cin >> money >> coin;
	if (coin == 'y')
		cout << "You have " << money * yen_dollar << " dollars.\n";
	else if (coin == 'e')
		cout << "You have " << money * euro_dollar << " dollars.\n";
	else if (coin == 'p')
		cout << "You have " << money * pound_dollar << " dollars.\n";
	else
		cout << "Incorrect input\n";
	keep_window_open();
    return 0;
}
maybe try instead to assign it to a string , which you would compare the last character wether is e,y,p , then take the string from 0 to string.size() -2 and convert to a double , then you do the conversion for currency. There is other option as well.
Hi,

56e could be construed as a double, doubles can have this format: 56e3 which is 56'000 . So your money (56e) is still 56, but there is now no value for coin :+)

You could prompt for the two values separately if that fits in with the requirements.
Last edited on
Oh yeah! Thank you for your help guys! :)
Topic archived. No new replies allowed.