# Currency Conversion Program

• 04-18-2002
kgraw21
Currency Conversion Program
This is the problem:

Expand the "Currency Conversion" program to read in the conversion rates
from a file, rather than hard coding values. The input file should include
the currency name and its currency conversion rate. The program should be
able to read up to 20 currencies and their conversion rates, and present
menus of the proper length to the user. The program's error checking should
allow for varying number of currencies. Insert comments in the program to
document the program internally.

This is what I have for the first currency conversion program:

/* Currency Conversion */

/* this program displays five currencies */
/* and their equivalents to a US Dollar */

#include <stdio.h>

int main(void)

{
/* declare the variables */

USD = 1.0;
EGP1 = 4.62000;
AUD1 = 1.90791;
CHF1 = 1.67022;
JPY1 = 127.633;

/* print text to screen and tak input */

printf("\nPlease enter the US amount that you would like to convert: ");
scanf("%f", &USD);

/* do conversion */

EGP = USD * EGP1;
AUD = USD * AUD1;
CHF = USD * CHF1;
JPY = USD * JPY1;

/* output the results */

printf("\nUnited States Dollar: %.2f = %f Egypt pounds", USD, EGP);
printf("\nUnited States Dollar: %.2f = %f Australia",USD, AUD);
printf("\nUnited States Dollar: %.2f = %f Switzerland Francs", USD, CHF);
printf("\nUnited States Dollar: %.2f = %f Japan Yen", USD, JPY);
printf("\nUnited States Dollar: %.2f = %f Canada", USD, CAD);

getch();
return 0;
}

And this is what I have so far on the final conversion:
/* this program displays five currencies */
/* and their equivalents to a US Dollar */

# include <stdio.h>
#define CONVERSION 5
#define SIZE 5
#define i
long mult(int * start, int * end);
int main(void)

{

/* intitalize the total currencies */

const float [CONVERSION] [SIZE] =
{
{1, 1.90791, 1.67022, 127.633, 1.58318},
{1, 1.66622,131.916,1.58869,1.88158},
{1.66645,1,79.1707, 0.953424, 1.12928},
{0.00758266,0.0126347,1, 0.0120479,0.0142707},
{0.531360,0.885235,70.0618,0.844007,1}
};

/* print text to screen */

printf("Enter the a letter for your conversion\n");
printf("A. USD B.Australia\n");
printf("C. Switzerland D. Japan\n");
scanf("%d", &USD);

static char* conversion[CONVERSION] =

{"USD", "AUD","CHF", "JPY", "CAD"};

const float size[SIZE] =

{1.0, 1.90791, 1.67022, 127.633, 1.58318};

float currency_conversion[CONVERSION];
float size_conversion[SIZE];

long mult(int * start, int * end) /* use pointer arithmetic */
{
long total = 0;

while (start < end)
{
total += *start; /* add value to total */
total +=ar[i];
start++; /* advance pointer to next element */
}

for (a=0,i<CONVERSIONS;i++)
{

currency_conversion[i]= 0.0;

printf("United States Dollar: \$%.2f = %f Egypt pounds", USD, EGP);

printf("United States Dollar: \$%.2f = %f Australia",USD, AUD);

printf("United States Dollar: \$%.2f = %f Switzerland Francs",USD, CHF);

printf("United States Dollar: \$%.2f = %f Japan Yen", USD, JPY);

printf("United States Dollar: \$%.2f = %f Canada", USD, CAD);

default : printf("Press q to quit");
break;
}

getchar();
return 0;
}

This thing won't compile, please help!!!! And im running out of time!!!

:confused: :confused: :confused:
• 04-18-2002
Bull
your first one compiled for me first time, what kinda errors are you getting when you try to compile it?
• 04-18-2002
kgraw21
The first program will complile, but then I am supposed to add on and im not sure if im doing the second right. I have corrected some of the spelling errors.
• 04-19-2002
tidda
i had done a similar thing in the past converting american dollars to canadian and vice versa. We used to take the value for conversion (called peg-rate) from a database, cause it used to change regularly.
• 04-19-2002
kgraw21
Tidda, do you have a example?
• 04-19-2002
Salem
It basically means you start with a text file containing say

USD 1.0
AUD 1.90791
CHF 1.67022
JPY 127.633