# Thread: Yen to Dollars conversion problem

1. ## Yen to Dollars conversion problem

I am trying to build a program that inputs deposits into an array by dollar amount, and displays them back in both dollars and Yen. I successfully built the program in C, but for some reason I can't figure it out in C++. What is wrong here?

Code:
```// Evaluate Yen
#include <iostream>

using namespace std;

const int MAX_CURRENCYS = 100;          // Max number of Bank Deposits
const float DOLLARS_TO_YEN = 102.2;   // 1 Dollar = 102.2 Yen

// Function prototypes
void readDollars ( float Dollars[], int count );
void DollarsToYen ( float Dollars[], float Yen[], int count );
void displayData ( float Dollars[], float Yen[], int count );

int main (void)
{
int nums;               // Actual number of  deposits
float Dollars[MAX_CURRENCYS];    //Dollars
float Yen[MAX_CURRENCYS];      // Yen

// Prompt the user for the number of deposits.
cout << endl << "\n Enter the number of  deposits: ";
cin >> nums;

// Read the amount in each deposit .

// Convert Dollars to Yen.
DollarsToYen(Dollars,Yen,nums);

// Display the amount in each deposit
displayData(Dollars,Yen,nums);

return 0;
}

// read number of Dollars in each  account from the keyboard

void readDollars ( float Dollars[], int count )
{
int j;
cout << "Enter the  dollar amount for each : ";
for ( j = 0; j < count; j++ )
cin >> Dollars[j];
}

//gives number of Yen in each account

void DollarsToYen ( float Dollars[], float Yen[], int count )
{
int j;
for ( j = 0; j < count; j++ );
Yen[j]=Dollars[j]*DOLLARS_TO_YEN;

}

// displays the amount in each account in both Dollars and Yen

void displayData ( float Dollars[], float Yen[], int count )
{
int j;
cout <<  "\n Dollars       Yen     \n" << endl;
for ( j=0;j<count;j++)
{
cout << "  %7.2f        %7.2f   \n" << Dollars[j] << Yen[j];
}
}```

2. Hmm I have another version setup with setw, but when I try to compile dev gives me an "outdated header" error with the iomanip?

3. Make sure you type <iomanip> and not <iomanip.h> (or <iostream.h>).

That was not my only problem fortunately. I'm not getting values to display still.

Code:
```// Evaluate Yen
#include <iostream>
#include <iomanip>
using namespace std;

const int MAX_CURRENCYS = 100;          // Max number of Bank Deposits
const float DOLLARS_TO_YEN = 102.2;   // 1 Dollar = 102.2 Yen

// Function prototypes
void readDollars ( float Dollars[], int count );
void DollarsToYen ( float Dollars[], float Yen[], int count );
void displayData ( float Dollars[], float Yen[], int count );

int main (void)
{
int nums;               // Actual number of  deposits
float Dollars[MAX_CURRENCYS];    //Dollars
float Yen[MAX_CURRENCYS];      // Yen

// Prompt the user for the number of deposits.
cout << endl << "\n Enter the number of  deposits: ";
cin >> nums;

// Read the amount in each deposit .

// Convert Dollars to Yen.
DollarsToYen(Dollars,Yen,nums);

// Display the amount in each deposit
displayData(Dollars,Yen,nums);

return 0;
}

// read number of Dollars in each  account from the keyboard

void readDollars ( float Dollars[], int count )
{
int j;
cout << "Enter the  dollar amount for each : ";
for ( j = 0; j < count; j++ )
cin >> Dollars[j];
}

//gives number of Yen in each account

void DollarsToYen ( float Dollars[], float Yen[], int count )
{
int j;
for ( j = 0; j < count; j++ );

}

// displays the amount in each account in both Dollars and Yen

void displayData ( float Dollars[], float Yen[], int count )
{
int j;
cout << "\n Dollars       Yen  \n" << endl;
for ( j=0;j<count;j++)
{
cout << setw(4) << j+1 << setw(7) << "" << setprecision(12) << "" << endl;
}
}```
Thanks

5. Well, gee. You might want to do something useful with your arrays in these functions:

Code:
```//gives number of Yen in each account

void DollarsToYen ( float Dollars[], float Yen[], int count )
{
int j;
for ( j = 0; j < count; j++ );

}

// displays the amount in each account in both Dollars and Yen

void displayData ( float Dollars[], float Yen[], int count )
{
int j;
cout << "\n Dollars       Yen  \n" << endl;
for ( j=0;j<count;j++)
{
cout << setw(4) << j+1 << setw(7) << "" << setprecision(12) << "" << endl;
}
}```

6. Code:
```
//gives number of Yen in each account

void DollarsToYen ( float Dollars[], float Yen[], int count )
{
int j;
for ( j = 0; j < count; j++ );
Yen[j]=Dollars[j]*DOLLARS_TO_YEN;
}

// displays the amount in each account in both Dollars and Yen

void displayData ( float Dollars[], float Yen[], int count )
{
int j;
cout << "\n Dollars       Yen  \n" << endl;
for ( j=0;j<count;j++)
{
cout << setw(4)<< j+1 << setw(7) << "" << setprecision(12) << "" << endl;
cout << Dollars[j] << Yen[j] << endl;
}
}```

7. setprecision(12)! Did you read what setprecision actually does?

8. Thank you for your help. I get the correct dollar amount displayed back out of the array, but the Yen values appear to be arbitrary. For example, if I enter 2 Deposits, both at 1 Dollar and 1 Dollar, I get back from the array (despite having set setprecision(3)) 3.21e-039 (for the first deposit), then for the second deposit it simply displays "0" in Yen. What can I do to correct this?

Code:
```// Evaluate Yen
#include <iostream>
#include <iomanip>
using namespace std;

const int MAX_CURRENCYS = 100;          // Max number of Bank Deposits
const float DOLLARS_TO_YEN = 102.2;   // 1 Dollar = 102.2 Yen

// Function prototypes
void readDollars ( float Dollars[], int count );
void DollarsToYen ( float Dollars[], float Yen[], int count );
void displayData ( float Dollars[], float Yen[], int count );

int main (void)
{
int nums;               // Actual number of  deposits
float Dollars[MAX_CURRENCYS];    //Dollars
float Yen[MAX_CURRENCYS];      // Yen

// Prompt the user for the number of deposits.
cout << endl << "\n Enter the number of  deposits: ";
cin >> nums;

// Read the amount in each deposit .

// Convert Dollars to Yen.
DollarsToYen(Dollars,Yen,nums);

// Display the amount in each deposit
displayData(Dollars,Yen,nums);

return 0;
}

// read number of Dollars in each  account from the keyboard

void readDollars ( float Dollars[], int count )
{
int j;
cout << "Enter the  dollar amount for each : ";
for ( j = 0; j < count; j++ )
cin >> Dollars[j];
}

//gives number of Yen in each account

void DollarsToYen ( float Dollars[], float Yen[], int count )
{
int j;
for ( j = 0; j < count; j++ );
Yen[j]=Dollars[j]*DOLLARS_TO_YEN;
}

// displays the amount in each account in both Dollars and Yen

void displayData ( float Dollars[], float Yen[], int count )
{
int j;
cout << "\n    Dollars       Yen  \n" << endl;
for ( j=0;j<count;j++)
{
cout << setw(1) << j+1 << "     " << setprecision(3) << Dollars[j] << "          " << setprecision(3) << Yen[j] << endl;
}
}```
-JJ

9. Code:
`for ( j = 0; j < count; j++ );`

10. Commenting that out of the DollarsToYen function correctly displays the Yen amount, but for only one deposit. Every deposit after is still listed as 0.

11. Originally Posted by JJohnson
Commenting that out of the DollarsToYen function correctly displays the Yen amount, but for only one deposit. Every deposit after is still listed as 0.
Look at it again. Notice what has been bolded and re-dyed, and ponder its existence.