if statement - Why does my program give me the excess output? C program -


i've made program cheque generator. whatever amount input in scanf output in words. example if to input "1234.56" output "one thousand 2 hundred thirty 4 dollars , ... 56 cents", or if wanted input amount "0.01" output "zero dollars , ... 1 cents". program works perfectly, there minor issue, if wanted input amount "9909" output "nine thousand 9 hundred ninety 9 dollars , ... 0 cents". output should "nine thousand 9 hundred 9 dollars , ... 0 cents". please help!

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 (c == 0 && b == 0 && == 0){         printf("zero dollars , ... %d cents\n", printcents);     }     else{         if (a > 0){              printnum(a);               printf("thousand ");         }         if (b > 0){             printnum(b);             printf("hundred ");         }         printnum2(c);            if (d >= 0){             printnum(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("nineteen ");     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 "); } 

i have been coding month apologize simple errors.

after have calculated b , adjusted inclusive 9, else case, sets c 9 (hence ninety output) , d 0, afterwards sets d 9 (hence nine in output). think mixed c , d in else case.


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 -