Working with decimal places and one other language thing...........
Aug 27, 2015 at 9:24am UTC
Hi guys,
I have two questions about the code below:
1) How do i change the code to display the decimal values correctly?
2) Imagine the exchange rate was exactly one dollar to one pound. Then the text should be "1 Pound = 1 Dollar" and not "1 Pounds = 1 Dollars".
How does one automatically account for this? I have a feeling it involves "if" & "else" and "<" & ">" or something but i have no idea how to formulate it!
Thanks! ..........D
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include "stdafx.h"
#include <iostream>
using namespace std;
#define DOLLARS 1
#define YEN_PER_DOLLAR 122
#define POUNDS_PER_DOLLAR 0.7
int main()
{
int YEN_DOLLAR = YEN_PER_DOLLAR / DOLLARS;
int POUND_DOLLAR = POUNDS_PER_DOLLAR / DOLLARS;
cout << YEN_DOLLAR << " Yen = " << DOLLARS << " Dollars" << endl;
cout << POUND_DOLLAR << " Pounds = " << DOLLARS << " Dollars" << endl;
return 0;
}
Last edited on Aug 27, 2015 at 9:25am UTC
Aug 27, 2015 at 9:59am UTC
float POUND_DOLLAR = POUNDS_PER_DOLLAR / DOLLARS;
Aug 27, 2015 at 10:04am UTC
1 2 3 4 5 6 7 8
cout << POUND_DOLLAR;
if ( POUND_DOLLAR == 1 )
cout << " Pound = " ;
else
cout << " Pounds = " ;
cout << DOLLARS << " Dollars" << endl;
Last edited on Aug 27, 2015 at 10:58am UTC
Aug 27, 2015 at 10:26am UTC
Thanks!!
Only: the last code example you give doesn't work (for me).
However, if i remove the curly braces on lines 3 & 7, it works!!
???
Aug 27, 2015 at 10:58am UTC
Yeah, my blooper. Delete the braces because they prevent 'entry' to the branch. 1000 pardons :-(
Aug 27, 2015 at 11:02am UTC
Thanks dude! :)
Topic archived. No new replies allowed.