mercredi 30 mars 2016

Converting Check Amount to Words , working code need modification

Hello This code was given to us in class, and I don't quite understand it and I currently cant see my professor before my assignment is due.

I need to expand this code to convert up to $1,000,000 Not the intended $99.99

Any help that you guys can offer would be very helpful.

the code is in c

#include<stdio.h>

int main(void)
{
    char *digits[ 10 ] = {"", "ONE", "TWO", "THREE", "FOUR",
        "FIVE", "SIX", "SEVEN", "EIGHT", "NINE"};
    char *teens[ 10 ] = {"TEN", "ELEVEN", "TWELVE", "THIRTEEN",
        "FOURTEEN", "FIFTEEN", "SIXTEEN",
        "SEVENTEEN", "EIGHTEEN", "NINETEEN"};
    char *tens[ 10 ] = {"", "TEN", "TWENTY", "THIRTY", "FORTY",
        "FIFTY", "SIXTY", "SEVENTY", "EIGHTY",
        "NINETY"};

    int dollars;
    int cents;
    int digit1;
    int digit2;

    printf("%s", "Enter the check amount ( 0.00 to 99.99 ): ");
    scanf("%d%d", &dollars, &cents);
    puts("\nThe check amount in words is:" );

    if ( dollars < 10 ){
        printf("%s ", digits[ dollars ]);
    }
    else if ( dollars < 20 ){
        printf("%s ", teens[dollars - 10]);
    }
    else {
        digit1 = dollars / 10;
        digit2 = dollars % 10;

        if ( 0 == digit2 ){
            printf("%s ", tens[digit1]);
        }
        else {
            printf("%s-%s ", tens[digit1], digits[digit2]);
        }
    }

    printf("and %d / 100\n", cents);
}

Aucun commentaire:

Enregistrer un commentaire