/* this programme displays the amount entered in digits to words*/
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
double total();
int readNocoins(char str[]);
double denomination(double);
void crores(int,char[][12]);
void lakhs(int,char[][12]);
void thousands(int,char[][12]);
void hundreds(int,char[][12]);
void tens(int,char[][12]);
int main() /* MAIN FUNCTION */
{
double dsum,dcount10rs;
clrscr();
dsum=total();
printf("TOTAL RUPEES=%lf\n",dsum);
denomination(dsum);
getch();
}
double total()
{
int icount5ps,icount10ps,icount20ps,icount25ps,icount50ps,icount1rs,icount2rs,icount5rs,icount10rs;
char ccount[10];
printf("\nenter the count of 5ps\n");
scanf("%s",ccount);
icount5ps=readNocoins(ccount);
printf("\nenter the count of 10ps\n"); scanf("%s",ccount);
icount10ps=readNocoins(ccount);
printf("\nenter the count of 20ps\n");
scanf("%s",ccount);
icount20ps=readNocoins(ccount);
printf("\nenter the count of 25ps\n");
scanf("%s",ccount);
icount25ps=readNocoins(ccount);
printf("\nenter the count of 50ps\n");
scanf("%s",ccount);
icount50ps=readNocoins(ccount);
printf("\nenter the count of 1rs\n");
scanf("%s",ccount);
icount10rs=readNocoins(ccount);
return ((icount5ps)*.05)+((icount10ps)*.10)+((icount20ps)*.20)+((icount25ps)*.25)+((icount50ps)*.50)+((icount1rs)*1)+((icount2rs)*2)+((icount5rs)*5)+((icount10rs)*10);
}
int readNocoins(char str[])
{
int iindex=0;
while(str[iindex]!='\0')
{
if(!isdigit(str[iindex]))
{
printf("\nERROR: INVALID INPUT.\nTRY AGAIN\n");
exit(0);
}
iindex++;
}
return(atoi(str));
}
double denomination(double dsum) /* FUNCTION TO PRINT THE DENOMINATION IN WORDS */
{
char inwords[][12]={"one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
int idecimal,itemp,ifraction;
itemp=idecimal=dsum;
ifraction=(dsum-idecimal)*100;
crores(idecimal%1000000000,inwords);
lakhs(idecimal%10000000,inwords);
thousands(idecimal%100000,inwords);
hundreds(idecimal%1000,inwords);
if(idecimal%1000&&idecimal%100&&idecimal/10)
printf("and");
tens(idecimal%100,inwords);
if(idecimal/1)
printf(" rupees ");
if(ifraction)
{
tens(ifraction,inwords);
81,1 39%
printf(" paise ");
}
printf(" only\n");
}
void tens(int ten,char inwords[][12]) /* FUNCTION TO PRINT THE TENS PART OF THE TOTAL IN WORDS */
{
int iones,itens;
iones=ten%10;
itens=ten-iones;
switch(itens)
{
case 20:printf(" twenty ");
break;
case 30:printf(" thirty ");
break;
case 40:printf(" fourty ");
break;
case 50:printf(" fifty ");
break;
case 60:printf(" sixty ");
break;
case 70:printf(" seventy ");
break;
case 80:printf(" eighty ");
break;
case 90:printf(" ninety ");
break;
}
if(ten<20&&ten)
{
printf(" %s ",inwords[ten-1]);
}
else if(iones)
{
printf(" %s ",inwords[iones-1]);
}
}
}
void hundreds(int hundred,char inwords[][12]) /* FUNCTION TO PRINT THE HUNDREDS PART OF THE TOTAL IN WORDS */
{
tens(hundred/100,inwords);
if(hundred/100)
{
printf(" hundred ");
}
}
void thousands(int thousand,char inwords[][12]) /* FUNCTION TO PRINT THE THOUSANDS PART OF THE TOTAL IN WORDS */
{
tens(thousand/1000,inwords);
if(thousand/1000)
{
printf(" thousand ");
}
}
void lakhs(int lakh,char inwords[][12]) /* FUNCTION TO PRINT THE LAKHS PART OF THE TOTAL IN WORDS */
{
tens(lakh/100000,inwords);
if(lakh/100000)
{
printf(" lakhs ");
}
}
void crores(int crore,char inwords[][12]) /* FUNCTION TO PRINT THE CRORES PART OF THE TOTAL IN WORDS */
{
tens(crore/10000000,inwords);
if(crore/10000000)
{
printf(" crores ");
}
}
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
double total();
int readNocoins(char str[]);
double denomination(double);
void crores(int,char[][12]);
void lakhs(int,char[][12]);
void thousands(int,char[][12]);
void hundreds(int,char[][12]);
void tens(int,char[][12]);
int main() /* MAIN FUNCTION */
{
double dsum,dcount10rs;
clrscr();
dsum=total();
printf("TOTAL RUPEES=%lf\n",dsum);
denomination(dsum);
getch();
}
double total()
{
int icount5ps,icount10ps,icount20ps,icount25ps,icount50ps,icount1rs,icount2rs,icount5rs,icount10rs;
char ccount[10];
printf("\nenter the count of 5ps\n");
scanf("%s",ccount);
icount5ps=readNocoins(ccount);
printf("\nenter the count of 10ps\n"); scanf("%s",ccount);
icount10ps=readNocoins(ccount);
printf("\nenter the count of 20ps\n");
scanf("%s",ccount);
icount20ps=readNocoins(ccount);
printf("\nenter the count of 25ps\n");
scanf("%s",ccount);
icount25ps=readNocoins(ccount);
printf("\nenter the count of 50ps\n");
scanf("%s",ccount);
icount50ps=readNocoins(ccount);
printf("\nenter the count of 1rs\n");
scanf("%s",ccount);
icount10rs=readNocoins(ccount);
return ((icount5ps)*.05)+((icount10ps)*.10)+((icount20ps)*.20)+((icount25ps)*.25)+((icount50ps)*.50)+((icount1rs)*1)+((icount2rs)*2)+((icount5rs)*5)+((icount10rs)*10);
}
int readNocoins(char str[])
{
int iindex=0;
while(str[iindex]!='\0')
{
if(!isdigit(str[iindex]))
{
printf("\nERROR: INVALID INPUT.\nTRY AGAIN\n");
exit(0);
}
iindex++;
}
return(atoi(str));
}
double denomination(double dsum) /* FUNCTION TO PRINT THE DENOMINATION IN WORDS */
{
char inwords[][12]={"one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"};
int idecimal,itemp,ifraction;
itemp=idecimal=dsum;
ifraction=(dsum-idecimal)*100;
crores(idecimal%1000000000,inwords);
lakhs(idecimal%10000000,inwords);
thousands(idecimal%100000,inwords);
hundreds(idecimal%1000,inwords);
if(idecimal%1000&&idecimal%100&&idecimal/10)
printf("and");
tens(idecimal%100,inwords);
if(idecimal/1)
printf(" rupees ");
if(ifraction)
{
tens(ifraction,inwords);
81,1 39%
printf(" paise ");
}
printf(" only\n");
}
void tens(int ten,char inwords[][12]) /* FUNCTION TO PRINT THE TENS PART OF THE TOTAL IN WORDS */
{
int iones,itens;
iones=ten%10;
itens=ten-iones;
switch(itens)
{
case 20:printf(" twenty ");
break;
case 30:printf(" thirty ");
break;
case 40:printf(" fourty ");
break;
case 50:printf(" fifty ");
break;
case 60:printf(" sixty ");
break;
case 70:printf(" seventy ");
break;
case 80:printf(" eighty ");
break;
case 90:printf(" ninety ");
break;
}
if(ten<20&&ten)
{
printf(" %s ",inwords[ten-1]);
}
else if(iones)
{
printf(" %s ",inwords[iones-1]);
}
}
}
void hundreds(int hundred,char inwords[][12]) /* FUNCTION TO PRINT THE HUNDREDS PART OF THE TOTAL IN WORDS */
{
tens(hundred/100,inwords);
if(hundred/100)
{
printf(" hundred ");
}
}
void thousands(int thousand,char inwords[][12]) /* FUNCTION TO PRINT THE THOUSANDS PART OF THE TOTAL IN WORDS */
{
tens(thousand/1000,inwords);
if(thousand/1000)
{
printf(" thousand ");
}
}
void lakhs(int lakh,char inwords[][12]) /* FUNCTION TO PRINT THE LAKHS PART OF THE TOTAL IN WORDS */
{
tens(lakh/100000,inwords);
if(lakh/100000)
{
printf(" lakhs ");
}
}
void crores(int crore,char inwords[][12]) /* FUNCTION TO PRINT THE CRORES PART OF THE TOTAL IN WORDS */
{
tens(crore/10000000,inwords);
if(crore/10000000)
{
printf(" crores ");
}
}
No comments:
Post a Comment