input - How to make my output show only whats needed with my cheque generator program for c -


i have made program can output whatever numeral inputted in convert words instead of numerals example if input "1234.56" convert "one thousand 2 hundred thirty 4 dollars , ... 56 cents". cents should in numerals. far works great, if put in amount less 1 thousand excess words such "thousand" or "hundred" in there. example if input "15.77" output "thousand hundred fifteen dollars , ... 77 cents". don't want thousand or hundred there, without perfect!

the code follows:

#include <stdio.h>  void printnum(int); void printnum2(int); void printnum3(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.01 || 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;          printnum(a);  //printing variables in thousands, hundreds, tens or ones categories.         printf("thousand ");         printnum(b);         printf("hundred ");         printnum2(c);         printf("");         printnum3(d);         printf("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 "); }  void printnum3(int x) {     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 ");  } 

i have been coding 1 month if seems made simple mistakes that's why.

you need add conditionals around printfs:

if (a > 0) {     printnum(a);  //printing variables in thousands, hundreds, tens or ones categories.     printf("thousand "); } 

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 -