1. ## dollars to yen.

Hi all-
I am learning arrays this week and I am confused how to use them. My program compiles but stops executing after I enter the "dollar amount for each." If anyone could help, it would be great. Thanks.
Code:
```#include <stdio.h>

const int MAX_CURRENCYS=100;

void readDollars ( float Dollars[0], int count);
void DollarsToYen ( float Dollars[0], float Yen[0], int count);
void displayData ( float Dollars[0], float Yen[0], int count);

int main (void)
{
int count;
float Dollars[MAX_CURRENCYS],
Yen[MAX_CURRENCYS];

printf("Enter the number of deposits: ");
scanf("%d",&count);

DollarsToYen(Dollars,Yen,count);

displayData(Dollars,Yen,count);

return 0;
}
void readDollars (float Dollars[0], int count )
{
int j;
for (j=0;j<count;j++)
printf("Enter the dollar amount for each: ");
scanf("%d", Dollars[0]);
}
void DollarsToYen (float Dollars[0], float Yen[0], int count)
{
int j;
for (j=0;j<count;j++)
Yen[0]=Dollars[0]*102;
}
void displayData (float Dollars[0], float Yen[0], int count)
{
int j;
for(j=0;j<count;j++)
printf("\n   Dollars    Yen    \n");
printf("  %7f  %12f\n", j+1);
}```

2. Let's some general things first.
Code:
`int array[10];`
This code declares an array of integers.The size of the array is ten,so ten integers can be stored there.Remember that we starting counting by zero.so the first element is
Code:
`array[0]`
and the last element is
Code:
`array[9]`
9 comes from 10-1 .

In order to access the i-th element of an array and set this element equal to five i would write this
Code:
`array[i] = 5;`
As you already know we access arrays by loops.So if i want to fill all the array with five,in other words set all elements of it equal to five i would write this
Code:
```int i;
for( i = 0 ; i < 10 ; i++)
{
array[i] = 5;
}```
When i want to pass an array as argument to a function i would write this
Code:
```#include <stdio.h>
#include <stdlib.h>

void myFunction(int *array , int n);
void print(int *array , int n);

int main(void)
{
int n = 10;
int array[n];
myFunction(array,n);
print(array,n);
return 0;
}

void myFunction(int *array , int n)
{
int i;
for( i = 0 ; i < n ; i++)
{
array[i] = 5;
}
}

void print(int *array , int n)
{
int i;
for( i = 0 ; i < n ; i++)
{
printf("%d\n",array[i]);
}
}```
we pass as an argument the pointer of the array.An array is a pointer to the first element of the array.Do not assume though that arrays and pointers are equivalent

3. Ok. I've got it to here. Why do I get all zeros for answers? Thanks.

Code:
```#include <stdio.h>
#include <iomanip>

const int MAX_S = 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 count;               // Actual number of  deposits */
float Dollars[MAX_S],    /* Dollars  */
Yen[MAX_S];      /* Yen */

/* Prompt the user for the number of deposits. */
printf("\n Enter the number of  deposits: ");
scanf("%d", &count);

// Read the amount in each deposit .

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

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

return 0;
}

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

void readDollars ( float Dollars[], int count )
{
int j;
for ( j = 0; j < count; j++ )
printf("Enter the  dollar amount for each : ");
scanf("%f", &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;
for (  j = 0; j < count; j++ )
printf(" \$%.2f, %.2f", Dollars[j], Yen[j]);

}```

4. Code:
```printf("Enter the  dollar amount for each : ");
for ( j = 0; j < count; j++ )
scanf("%f", &Dollars[j]);```

5. yes, thank you. i did figure that out, but my new code gives me the correct exchange for the first dollar amount only. after that, it gives zeros. also, i can't figure out how to make columns. thanks for any help.

Code:
```#include <stdio.h>
#include <iomanip>

/* 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 count;               // Actual number of  deposits */
float Dollars[100],    /* Dollars  */
Yen[100];      /* Yen */

/* Prompt the user for the number of deposits. */
printf("\n Enter the number of  deposits: ");
scanf("%d", &count);

// Read the amount in each deposit .

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

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

return 0;
}

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

void readDollars ( float Dollars[], int count )
{
int j;
printf("Enter the  dollar amount for each : ");
scanf("%f", &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] * 102.2;
}

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

void displayData ( float Dollars[], float Yen[], int count )
{
int j;
for (  j = 0; j < count; j++ )
printf("    \$%.2f,    %.2f",      Dollars[j], Yen[j]);

}```

6. You have made some effort to indent your code, and that is good, but it can still be improved, e.g.,
Code:
```#include <stdio.h>
#include <iomanip>

/* 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 count;           /* Actual number of deposits */
float Dollars[100],  /* Dollars  */
Yen[100];      /* Yen */

/* Prompt the user for the number of deposits. */
printf("\n Enter the number of  deposits: ");
scanf("%d", &count);

// Read the amount in each deposit .

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

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

return 0;
}

/* read number of Dollars in each  account from the keyboard */
void readDollars( float Dollars[], int count )
{
int j;
printf("Enter the  dollar amount for each : ");
scanf("%f", &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] * 102.2;
}

/* displays the amount in each account in both Dollars and Yen */
void displayData( float Dollars[], float Yen[], int count )
{
int j;
for ( j = 0; j < count; j++ )
printf("    \$%.2f,    %.2f", Dollars[j], Yen[j]);
}```
Notice that I also removed the many blank lines that you had. Generally, a single blank line is enough to separate groups of statements. If you want to separate functions with two or three blank lines, I guess that's okay, but generally having more than three blank lines hinders readability.

Next, I notice that in your readDollars function, you don't have a loop.

7. thanks laserlight. i got it to work!

Code:
```#include <stdio.h>
#include <iomanip>

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 count;
float Dollars[100],
Yen[100];

printf("\n Enter the number of  deposits: ");
scanf("%d", &count);

DollarsToYen(Dollars,Yen,count);

displayData(Dollars,Yen,count);

return 0;
}
void readDollars ( float Dollars[], int count )
{
int j;
printf("Enter the  dollar amount for each : ");
for ( j = 0; j < count; j++ )
scanf("%f", &Dollars[j]);
}
void DollarsToYen ( float Dollars[], float Yen[], int count )
{
int j;
for ( j = 0; j < count; j++ )
Yen[j] = Dollars[j] * 102.2;
}
void displayData ( float Dollars[], float Yen[], int count )
{
int j;
printf("\n     Dollars     Yen     \n");
for (  j = 0; j < count; j++ )
{
printf("      \$%.2f,    %.2f \n",      Dollars[j], Yen[j]);
}
}```

8. thanks click_here, also!