Program excuting w/ no errors but ignoring code!

I'm starting a money conversion program. I first wanted to test the yen conversion, and glad I did. Right after i make my choice of yen it ignores my next lines of code and completes with return 0;. Any help would be appreciated. I don't understand how to debug something that doesn't show errors yet.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  int main()
{
cout << "what would you like to convert today?\n";
cout << "Choice 1: Yen\n Choice 2: Dollars\n Please Make a selection by typing Yen or Dollars.\n";
string Yen;
string Dollars;
string Money;
string choice;
string yes, Yes,no,No;
cin >> Money;
if (Money == Yen){
	cout << "Ok you have selected, " << Money << "are you sure?\n Yes or No.";
	cin >> choice;
	if (choice == yes){
		int yenAmount;
		cin >> yenAmount;
		cout << yenAmount*.90;
	}
	else cout << "Sorry I don't understand.";
	}
	return 0;

}
It isn't ignoring anything, it's just executing according to the meaning of the code. In this if statement,
 
    if (Money == Yen)
we assume the user typed "yen", so the variable Money contains the value "yen". The variable Yen is a string which still has its default initial value, which is an empty string "".

So if (Money == Yen) becomes in effect a test of "yen" == "". Since they are not the same, the condition is false and the program resumes after the end of that if statement, and then terminates.

You could instead put: const string Yen = "yen"; give the variable the required initial value. Or simply delete that variable, and change the if statement to:
 
    if (Money == "yen")

that is, replace the variable Yen with the character string literal "yen".



Thx [b]Chervil[\b], I just started using literals, they seems more efficient.
Topic archived. No new replies allowed.