Please do the following program in C language not C or C Wri

Please do the following program in C language (not C++ or C#).

Write a command-line program that will write a check. You will need to convert a string representation of a number into its English-word equivalent. Do this by using each digit of the amount string as indexes into string tables (see sample code). The program must run at the command line for any value up to $9999.99. Assume all values will be of the form $X.YY, where X is one to 4 digits. Test your program with several values. For example C Windows system32cmd.exe RUsers John Desktop General CRDebugspay 2475.41 OMMAND LINE USAGE: pay kiname

Solution

below is the code exactly as per your output requirements. Save the code as Pay.C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


void amountInWords(char *num)
{
int len = strlen(num); // Get number of digits in given number

if (len == 0) {
fprintf(stderr, \"empty string\ \");
return;
}
if (len > 4) {
fprintf(stderr, \"Length more than 4 is not supported\ \");
return;
}

char *single_digits[] = { \"zero\", \"one\", \"two\", \"three\", \"four\",
\"five\", \"six\", \"seven\", \"eight\", \"nine\"};

char *two_digits[] = {\"\", \"ten\", \"eleven\", \"twelve\", \"thirteen\", \"fourteen\",
\"fifteen\", \"sixteen\", \"seventeen\", \"eighteen\", \"nineteen\"};

char *tens_multiple[] = {\"\", \"\", \"twenty\", \"thirty\", \"forty\", \"fifty\",
\"sixty\", \"seventy\", \"eighty\", \"ninety\"};

char *tens_power[] = {\"hundred\", \"thousand\"};


// For single digit
if (len == 1) {
printf(\"%s\ \", single_digits[*num - \'0\']);
return;
}


while (*num != \'\\0\') {

//for more than 2 digits
if (len >= 3) {
if (*num -\'0\' != 0) {
printf(\"%s \", single_digits[*num - \'0\']);
printf(\"%s \", tens_power[len-3]);
}
--len;
}


else {
  
if (*num == \'1\') { // for numbers 10-19
int sum = *num - \'0\' + *(num + 1)- \'0\';
printf(\"%s\ \", two_digits[sum]);
return;
}

else if (*num == \'2\' && *(num + 1) == \'0\') { // for number 20
printf(\"twenty\ \");
return;
}

  
else { // remaining 21 to 99
int i = *num - \'0\';
printf(\"%s \", i? tens_multiple[i]: \"\");
++num;
if (*num != \'0\')
printf(\"%s \", single_digits[*num - \'0\']);
}
}
++num;
}
}
int main(int argc, char *argv[])
{
if(argc!=4)
{
printf(\"COMMAND LINE PARAMETERS : pay <lastname> <firstname> $X.YY\");
return 1;
}

printf(\"\ Pay to the order of : %s %s\\t %s \ \", argv[1],argv[2],argv[3]);
int len=strlen(argv[3]);
char str[10];
memset(str, \'\\0\', sizeof(str));
stpcpy(str,argv[3]);
char amount[4];
char decimal[2];
int j=0;

for(int i=1;i<len;i++) // to get the numbers of the amount
{
   if(str[i]==\'.\')
   {
       flag=1;
   }
   if(flag==0)
   {
       amount[i-1]=str[i];
   }
   else
   {
       decimal[j]=str[i];
       j++;
   }
}
  
amountInWords(amount);
printf(\" and %s /100\",decimal);
printf(\"Signed By : Boss Man\");

return 0;
}

kindly give feedback nicely & feel free to ask if yo have any doubt :)

Please do the following program in C language (not C++ or C#). Write a command-line program that will write a check. You will need to convert a string represent
Please do the following program in C language (not C++ or C#). Write a command-line program that will write a check. You will need to convert a string represent
Please do the following program in C language (not C++ or C#). Write a command-line program that will write a check. You will need to convert a string represent

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site