compilation - How to make my cheque generator output exactly what it is instead of "Zero" in C -


my cheque generator program has worked flawlessly input give make output numerals in words. example if input "1234.56" out put "one thousand 2 hundred thirty 4 dollars , ... 56 cents". whenever want output "1000" output "one thousand 0 dollars , ... 0 cents". not 1000 0 dollars, cents fine, wish rid of "zero" need in there moments such if type in "0.01" output "zero dollars , 1 cent".

the code follows:

#include <stdio.h>  void printnum(int); void printnum2(int); int main() {  int = 0; int b = 0; int c = 0; int d = 0;  int num = 0; int printcents; //to convert float "cents" integer.  float inclusive; float cents;  printf("welcome ipc144 cheque generator!!\n"); printf("pay order of... amahmood29 (018359133)\n"); printf("enter monetary value $0.01 $9999.99 inclusive: "); scanf("%f", &inclusive);  if(inclusive < 0.00 || inclusive >= 10000.00) {     printf("sorry, cannot create cheque amount, try again next time!\n");        } else {                                                  = inclusive / 1000;                          //this data replacing our variable diving whatever vaulue either 1000, 100, 10.     inclusive = inclusive - (a*1000);     b = inclusive / 100;      inclusive = inclusive - (b*100); if ( inclusive > 19 ){     c = inclusive / 10;      inclusive = inclusive - (c*10); } else {     c = inclusive;     d = 0; }     d = inclusive;     num = inclusive;     cents = (inclusive - num)*100; //to calculate our "cents" numerals.     printcents = cents;             /*printing if variables in thousands, hundreds, tens or ones categories.*/ if (a > 0){      printnum(a);       printf("thousand "); } if (b > 0){     printnum(b);     printf("hundred "); }     printnum2(c);    if (d > 0){     printnum(d);     printf("dollars , ... "); } else if (d == 0){     printf("zero dollars , ... "); }     printf("%d", printcents);     printf(" cents\n");     } }  void printnum(int x)  //created functions output various if statements. {  if ( x == 1)     printf("one "); else if ( x == 2)     printf("two "); else if (x == 3)     printf("three "); else if (x == 4)      printf("four "); else if (x == 5)     printf("five "); else if (x == 6)     printf("six "); else if (x == 7)     printf("seven "); else if (x == 8)     printf("eight "); else if (x == 9)     printf("nine ");  } void printnum2(int x) {  if ( x == 10)      printf("ten ");  else if ( x == 11)      printf("eleven ");  else  if ( x == 12)      printf("twelve ");  else if ( x == 13)      printf("thirteen ");  else if (x == 14)      printf("fourteen ");  else if (x == 15)      printf("fifteen ");  else if (x == 16)      printf("sixteen ");  else if (x == 17)      printf("seventeen ");  else if (x == 18)      printf("eighteen ");  else if (x == 19)      printf("ninteen ");  else if (x == 2)      printf("twenty ");  else if (x == 3)      printf("thirty ");  else if (x == 4)      printf("forty ");  else if (x == 5)      printf("fifty ");  else if (x == 6)      printf("sixty ");  else if (x == 7)      printf("seventy ");  else if (x == 8)      printf("eighty ");  else if (x == 9)      printf("ninety "); } 

various subtractions inclusive = inclusive - (c*10) suffering round-off error , therefore have tiny amount left when doing if (d > 0).

suggest rounding nearest 0.01. example: inclusive = round(100*(inclusive - (c*10)))/100.0 , other places.

or re-do in integer number of cents.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -