cout<<"Hello Programers! Please help.\n";

Hi, All! I am learning C++ and new to this forum. I hope we will be all be helpful to each other.

For my questions:

(1)___________________________________________________________________

When I run this program which converts USD to euros/yen depending on the user's choice, it runs properly when I use the inputs like 1y, 1 (return) y, and 1 (return) e, but when I use 1e, the program returns the else statement. Why is that?

Here is my program in int main;

const double ytd=1/360.0, etd=1/1.287;

double d=0;

char c='v';

cout<<"Please enter the amount of USD then the letter 'e' to be converted to euro or"<<
" letter 'y' to be converted to yen.\n";

cin>>d>>c;


switch (c){


case 'y':
cout<<"You have "<<d*ytd<<" yen\n";
break;

case 'e':
cout<<"You have "<<d*etd<<" euros\n";
break;


default:
cout<<"I do not know this currency.\n";
break;


/* ytd=yen to dollars
etd=euro to dollars
d=dollars
c=currency */
______________________________________________________________________


(2)___________________________________________________________________

I am trying to make a C++ program that would arrange three words in alphabetical order. Note that I did one for arranging three integers from least to greatest. Any help?
______________________________________________________________________


(3)___________________________________________________________________

Plus, why when I add/multiply/divide/subtract double numbers and store them into a double variable, it will store them as int?
_____________________________________________________________________

(4)__________________________________________________________________

Is this true? http://www.gidnetwork.com/b-61.html

____________________________________________________________________
And thanks.
Last edited on
1) When you input from cin>> it will give you everything until the first white space in a single burst. Therefore if you do this: cin >> d >> c; You will input everything up to the first white space in d, then the next set of stuff into c. This will happen even if the input doesn't really make sense. The validity checking of the inputs is up to you as the programmer.

2) words are made up of sets of characters. In your number version of the function I assume you use the < operator. That is, I bet you do if (a < b) somewhere. That works with characters too. 'a' is really less than 'b' which is less than 'c'. The only problem is that 'Z' is less than 'a' while 'z' is greater than 'a', so you'll probably want to use toupper or tolower to ensure that the cases match.
http://www.cplusplus.com/reference/cctype/toupper/

3) That doesn't happen. How do you know they are stored as ints? Is it because you don't have trailing zeros when you print it out? The console will automatically truncate the trailing zeros. You can use functions in <iomanip> to display additional zeros. Note that it is also possible that you are coming across integer division.

4) Yes, don't use system("anything"). Try cin.get() instead.
Thanks, all helped. And for number (3), I believe it was just a mistake in my code.
Topic archived. No new replies allowed.