Click here to Skip to main content
15,885,925 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
GOOD MORNING, ITS 2AM AND IM TIRED LOL.

C#
void convertNetPay(float netPay, char *netPayString)
{
    int numHuns, numTens, numOnes;
    char OnesTable[9][8]={"One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
    char ResultString[10+1];
    char TensTable[9][8] = {"Ten","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"};
    char TeensTable[9][10] {"Eleven","Twelve","Thirteen","fourteen","fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
    float cents;

    cents = netPay - int(netPay);

    strcpy(netPayString,"The sum of ");

    numHuns = int(netPay) / 100;

    if (numHuns > 0)
    {
    strcat(netPayString,OnesTable[numHuns-1]);
    strcat(netPayString," Hundred ");
    }
    int remainder =  int(netPay) % 100;
    /*if  (remainder ==0)
    {
        //do something
    }*/
         if ((remainder>=11) || (remainder<=19))
        {
            strcat(netPayString, TeensTable[remainder -11]);
        }
            else{
                numTens = int(netPay) % 100 / 10;
                numOnes = int(netPay) % 100 % 10;
                if (numTens > 0)
                {
                    strcat(netPayString,TensTable[numTens -1]);
                    strcat(netPayString," - ");
                }
                if (numOnes > 0)
                {
                    strcat(netPayString,OnesTable[numOnes-1]);
                    strcat(netPayString," Dollars and ");
                }
            cents = cents + 0.005;
            cents = cents * 100;

            sprintf(ResultString,"%d",int(cents));
            strcat(netPayString,ResultString);
            }
}


BASICALLY, I have to convert netpay (float to string).
Theoretically if I have 666.66, my program here should output the sum of "six hundred sixty-six and 66/100 dollars".
Any help is appreciated, thank you!
Posted

1 solution

Google is your friend: Be nice and visit him often. He can answer questions a lot more quickly than posting them here...

A very quick search gave over 2 million hits: number to english words c++[^]

In future, please try to do at least basic research yourself, and not waste your time or ours.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900