C++ this is the second problem Continuing the last one. thx a lot
C++ this is the second problem Continuing the last one. thx a lot
Problem 2*
Continuing the discussion of the previous example, we reiterate the importance of designing check-writing systems to prevent alteration of check amounts. One common security method requires that the check amount be written both in numbers, and spelled out in words as well. Even if someone is able to alter the numerical amount of the check, it is extremely difficult to change the amount in words. Many computerized check-writing systems do not print the amount of the check in words. Perhaps the main reason for this omission is the fact that most high-level languages used in commercial applications do not contain adequate string manipulation features. Another reason is that the logic for writing word equivalents of check amounts is somewhat involved. Write a C++ program that inputs a numeric check amount and writes the word equivalent of the amount.
For example, the amount 112.43 should be written as ONE HUNDRED TWELVE AND 43/100 DOLLARS. Your program should be able to handle amounts up to 1 million dollars.
#include
#include
char unit[4][33]={"","THOUSAND","MILLION"};
char low[10][33]={"ZERO","ONE","TWO","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE"};
char two[10][33]={"TEN","ELEVEN","TWELVE","THIRTTEN","FOURTEEN","FIFTEEN","SIXTEEN","SEVENTEEN","EIGHTEEN","NINETEEN"};
char high[10][33]={"ZERO","TEN","TWENTY","THIRTY","FORTY","FIFTY","SIXTY","SEVENTY","EIGHTY","NINETY"};
char hd[33]="HUNDRED";
void trans(int n,int deep)
{
char dig[100]={0};
if(n==0)return ;
if(n/100>0)
{
strcat(dig,low[n/100]);
strcat(dig," ");
strcat(dig,hd);
strcat(dig," ");
}
n%=100;
if(n==0)
{
;
}
else if(n0)
{
strcat(dig,unit[deep]);
strcat(dig," ");
}
printf("%s",dig);
}
void out(int n,int deep)
{
if(n==0)return;
out(n/1000,deep+1);
trans(n%1000,deep);
}
int main()
{
int sum=0;
int T,n=0,i;
char s[1000];
scanf("%s",s);
for(i=0;s[i]!='.';i++)n=n*10+s[i]-'0';
for(i++;s[i];i++)sum=sum*10+s[i]-'0';
if(n==0)
{
printf("ZERO ");
}
else out(n,0);
printf("AND %d/100",sum);
return 0;
}