1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
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);
}
}
|