This C program handles values only up to $99.99. Please modify to handle values up to $999.99. *****WOULD BE GRATEFUL IF YOU COULD HIGHLIGHT CHANGES MADE**** #include int main( void ) { // word equivalents of single digits char *digits[ 10 ] = { "", "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE"}; // word equivalents of 10-19 char *teens[ 10 ] = { "TEN", "ELEVEN", "TWELVE", "THIRTEEN", "FOURTEEN", "FIFTEEN", "SIXTEEN", "SEVENTEEN", "EIGHTEEN", "NINETEEN"}; // word equivalents of tens digits char *tens[ 10 ] = { "", "TEN", "TWENTY", "THIRTY", "FORTY", "FIFTY", "SIXTY", "SEVENTY", "EIGHTY", "NINETY"}; int dollars; // check dollar amount int cents; // check cents amount int digit1; // ones digit int digit2; // tens digit // get check amount printf( "%s", "Enter the check amount ( 0.00 to 99.99 ): " ); scanf( "%d.%d", &dollars, ¢s ); puts( "\nThe check amount in words is:" ); // print equivalent words if ( dollars < 10 ) { printf( "%s ", digits[ dollars ] ); } // end if else if ( dollars < 20 ) { printf( "%s ", teens[ dollars - 10 ] ); } // end else if else { digit1 = dollars / 10; // ones digit digit2 = dollars % 10; // tens digit // if ones digit is zero if ( 0 == digit2 ) { printf( "%s ", tens[ digit1 ] ); } // end if else { printf( "%s-%s ", tens[ digit1 ], digits[ digit2 ] ); } // end else } // end else printf( "and %d/100\n", cents ); } // end main
Hello,
This C program handles values only up to $99.99. Please modify to handle values up to $999.99. *****WOULD BE GRATEFUL IF YOU COULD HIGHLIGHT CHANGES MADE****
#include <stdio.h>
int main( void )
{
// word equivalents of single digits
char *digits[ 10 ] = { "", "ONE", "TWO", "THREE", "FOUR",
"FIVE", "SIX", "SEVEN", "EIGHT", "NINE"};
// word equivalents of 10-19
char *teens[ 10 ] = { "TEN", "ELEVEN", "TWELVE", "THIRTEEN",
"FOURTEEN", "FIFTEEN", "SIXTEEN",
"SEVENTEEN", "EIGHTEEN", "NINETEEN"};
// word equivalents of tens digits
char *tens[ 10 ] = { "", "TEN", "TWENTY", "THIRTY", "FORTY",
"FIFTY", "SIXTY", "SEVENTY", "EIGHTY",
"NINETY"};
int dollars; // check dollar amount
int cents; // check cents amount
int digit1; // ones digit
int digit2; // tens digit
// get check amount
printf( "%s", "Enter the check amount ( 0.00 to 99.99 ): " );
scanf( "%d.%d", &dollars, ¢s );
puts( "\nThe check amount in words is:" );
// print equivalent words
if ( dollars < 10 ) {
printf( "%s ", digits[ dollars ] );
} // end if
else if ( dollars < 20 ) {
printf( "%s ", teens[ dollars - 10 ] );
} // end else if
else {
digit1 = dollars / 10; // ones digit
digit2 = dollars % 10; // tens digit
// if ones digit is zero
if ( 0 == digit2 ) {
printf( "%s ", tens[ digit1 ] );
} // end if
else {
printf( "%s-%s ", tens[ digit1 ], digits[ digit2 ] );
} // end else
} // end else
printf( "and %d/100\n", cents );
} // end main
To handle values up to $999.99, you need to write more code for calculation.
Like you have done for 2 digit values, now, you need to do calculation for 3 digit values.
You need to divide user entered value by 100 and then need to use % operator and need to check result of that.
Step by step
Solved in 2 steps