Currency Conversion Program

This is a discussion on Currency Conversion Program within the C Programming forums, part of the General Programming Boards category; This is the problem: Expand the "Currency Conversion" program to read in the conversion rates from a file, rather than ...

  1. #1
    Registered User
    Join Date
    Apr 2002
    Posts
    3

    Unhappy 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 */

    float USD,EGP,AUD,CHF,JPY,CAD,EGP1,AUD1,CHF1,JPY1,CAD1;
    USD = 1.0;
    EGP1 = 4.62000;
    AUD1 = 1.90791;
    CHF1 = 1.67022;
    JPY1 = 127.633;
    CAD1 = 1.58318;

    /* 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;
    CAD = USD * CAD1;

    /* 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);
    float USD,AUD,CHF,JPY,CAD
    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");
    printf("E.Canada\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;
    }

    return total;
    getchar();
    return 0;
    }

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


  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    95
    your first one compiled for me first time, what kinda errors are you getting when you try to compile it?

  3. #3
    Registered User
    Join Date
    Apr 2002
    Posts
    3
    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.

  4. #4
    Registered User tidda's Avatar
    Join Date
    Mar 2002
    Posts
    37
    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.
    -tidda

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    3
    Tidda, do you have a example?

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,592
    It basically means you start with a text file containing say

    USD 1.0
    AUD 1.90791
    CHF 1.67022
    JPY 127.633
    CAD 1.58318

    > The program should be able to read up to 20 currencies and their conversion rates
    So
    #define SIZE 20
    float rates[SIZE];

    All you do is use fopen, fscanf etc to read each line from the file, and assign values to various array elements

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conversion of pointers to functions
    By hzmonte in forum C Programming
    Replies: 0
    Last Post: 01-20-2009, 12:56 AM
  2. Minute to hour/minute conversion program
    By Remius in forum C Programming
    Replies: 7
    Last Post: 12-29-2007, 07:39 AM
  3. Newbie Help: Currency Converter
    By Ashfury in forum C Programming
    Replies: 10
    Last Post: 11-06-2005, 12:21 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Help with variables (newbee)
    By stugatza in forum C Programming
    Replies: 7
    Last Post: 08-18-2004, 10:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21