GOOD MORNING, ITS 2AM AND IM TIRED LOL.
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>=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!