Working with decimal places and one other language thing...........

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
closed account (48T7M4Gy)
float POUND_DOLLAR = POUNDS_PER_DOLLAR / DOLLARS;
closed account (48T7M4Gy)
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
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!!

???
closed account (48T7M4Gy)
Yeah, my blooper. Delete the braces because they prevent 'entry' to the branch. 1000 pardons :-(
Thanks dude! :)
Topic archived. No new replies allowed.