C/C++ Language | Check Conversion

Sunday 16 December 2012


ATM machines are now used around the globe because it is the only and convenient way of getting cash immediately especially if you have emergencies. Nowadays, ATM machines are not just for personal banking, it is also used in paying your employees wages or sending money to your relatives. ATM is a card-to-cash basis transaction. Now, as I was thinking about this kind of program I come up with the idea of making a  program that converts the check figures into words to automate a billing system.

This program is used with selection statements and decision making statements namely If Statements and Switch case statements. The program also has a limit input of 100,000,000. Check out the codes below.


 1: #include <stdio.h>
   2:  #include <conio.h>
   3:   
   4:  main()
   5:  {
   6:   
   7:   
   8:  int num;
   9:  int num1,num2,num3,num4;
  10:   
  11:   
  12:  printf("\nEnter Numbers: ");
  13:  scanf("%d", &num);      
  14:            if ( num > 100000000 ) {
  15:            printf("\n\nYou have exceeded the maximum input of 100,000,000.\n");
  16:            }
  17:  if(num<=100000000)
  18:  {
  19:  num1=num/1000 % 10;
  20:  num2=num/100 % 10;
  21:  num3=num/10 % 10;
  22:  num4=num/1 % 10;
  23:   
  24:  switch(num1){
  25:  case 1:
  26:  printf(" one thousand") ;
  27:  break;
  28:   

  29:  case 2:
  30:  printf(" two thousand");
  31:  break;
  32:   
  33:  case 3:
  34:  printf(" three thousand");
  35:  break;
  36:   
  37:  }
  38:   
  39:  switch(num2){
  40:  case 1:
  41:  printf(" one hundred");
  42:  break;
  43:   
  44:  case 2:
  45:  printf(" two hundred");
  46:  break;
  47:   
  48:  case 3:
  49:  printf(" three hundred");
  50:  break;
  51:   
  52:  case 4:
  53:  printf(" four hundred") ;
  54:  break;
  55:   
  56:  case 5:
  57:  printf(" five hundred");
  58:  break;
  59:   
  60:  case 6:
  61:  printf(" six hundred");
  62:  break;
  63:   
  64:  case 7:
  65:  printf(" seven hundred");
  66:  break;
  67:   
  68:  case 8:
  69:  printf(" eight hundred");
  70:  break;
  71:   
  72:  case 9:
  73:  printf(" nine hundred");
  74:   
  75:  }
  76:   
  77:  if (num3==1&&num4==1){
  78:  printf(" eleven");
  79:  }
  80:  if (num3==1&&num4==2){
  81:  printf(" twelve");
  82:  }
  83:  if (num3==1&&num4==3){
  84:  printf(" thirteen");
  85:  }
  86:  if (num3==1&&num4==4){
  87:  printf(" fourteen");
  88:  }
  89:  if (num3==1&&num4==5){
  90:  printf(" fifteen");
  91:  }
  92:  if (num3==1&&num4==6){
  93:  printf(" sixteen");
  94:  }
  95:  if (num3==1&&num4==7){
  96:  printf(" seventeen");
  97:  }
  98:  if (num3==1&&num4==8){
  99:  printf(" eighteen");
 100:  }
 101:  if (num3==1&&num4==4){
 102:  printf(" nineteen");
 103:  }
 104:   
 105:  switch(num3){
 106:  case 1:
 107:  if(num3==1&&num4==0){
 108:  printf(" ten");
 109:  }
 110:  break;
 111:   
 112:  case 2:
 113:  printf(" twenty");
 114:  break;
 115:   
 116:  case 3:
 117:  printf(" thirty");
 118:  break;
 119:   
 120:  case 4:
 121:  printf("fourty");
 122:  break;
 123:   
 124:  case 5:
 125:  printf(" fifty");
 126:  break;
 127:   
 128:  case 6:
 129:  printf(" sixty");
 130:  break;
 131:   
 132:  case 7:
 133:  printf(" seventy");
 134:  break;
 135:   
 136:  case 8:
 137:  printf(" eighty");
 138:  break;
 139:   
 140:  case 9:
 141:  printf(" ninety");
 142:  break;
 143:   
 144:  }
 145:   
 146:  switch(num4){
 147:  case 1:
 148:  if(num4==1&&num3!=1){
 149:  printf(" one") ;
 150:  }
 151:  break;
 152:   
 153:  case 2:
 154:  if(num4==2&&num3!=1){
 155:  printf(" two") ;
 156:  }
 157:  break;
 158:   
 159:  case 3:
 160:  if(num4==3&&num3!=1){
 161:  printf(" three") ;
 162:  }
 163:  break;
 164:   
 165:  case 4:
 166:  if(num4==4&&num3!=1){
 167:  printf(" four") ;
 168:  }
 169:  break;
 170:   
 171:  case 5:
 172:  if(num4==5&&num3!=1){
 173:  printf(" five") ;
 174:  }
 175:  break;
 176:   
 177:  case 6:
 178:  if(num4==6&&num3!=1){
 179:  printf(" six") ;
 180:  }
 181:  break;
 182:   
 183:  case 7:
 184:  if(num4==7&&num3!=1){
 185:  printf(" seven") ;
 186:  }
 187:  break;
 188:   
 189:  case 8:
 190:  if(num4==8&&num3!=1){
 191:  printf(" eight") ;
 192:  }
 193:  break;
 194:   
 195:  case 9:
 196:  if(num4==9&&num3!=1){
 197:  printf(" nine") ;
 198:  }
 199:  break;
 200:  }
 201:  getch();
 202:  }
 203:  }


This program operates like this. It will ask the user to enter any amount. The inputs will be divided into four (4) memory namely num1, num2, num3, and num4. Take note that the input must not exceed to 100,000,000 because that's the limit of the program. That inputs will then be executed by the If statement which will do the equations in getting the percentage. Then, it will go through the switch case statements and look for the case that satisfies it. After that, the result will be posted. You have now converted the figures in your check into words automatically. Check out the sample output below.



   

Hope you learned something from this post. Feel free to leave a comment below. Thanks!


No comments:

Post a Comment

Please do leave a comment. It's gonna be a friendly conversation between programmers. Hope you do find our blog helpful. Thank you!

Related Posts Plugin for WordPress, Blogger...