Posted By

kshol on 09/28/19


Tagged

check writing c++


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

kshol


check writing


 / Published in: C++
 

This snippet passes in a check amount parameter, in dollars and cents including decimal point, up to 99999.99, and displays the amount written out in words as in writing a check. Run .exe from a command prompt, followed by a space and then the amount. This code was written in the Visual Studio IDE.

  1. #include <stdio.h>
  2. #include <process.h>
  3. #include <string.h>
  4. #include <io.h>
  5. #include <conio.h>
  6. #include <stdlib.h>
  7. #include <fcntl.h>
  8. #include <process.h>
  9. #include <sys\stat.h>
  10. #include <dos.h>
  11. #include <ctype.h>
  12. #include <iostream>
  13. using namespace std;
  14. int main(int argc, char* argv[])
  15. {
  16. char ch;
  17. char outnum[12];
  18. int length;
  19. int output;
  20. int i;
  21. int outleng;
  22. char string[9];
  23. char buf[9];
  24. int out = 0;
  25.  
  26. strcpy_s(string, argv[1]);
  27. strcpy_s(buf, string);
  28. length = strlen(string);
  29. i = 0;
  30. out = 0;
  31.  
  32. do {
  33. ch = buf[i];
  34. strcpy_s(outnum, "");
  35. if (length == 9 || length == 7 || length == 6 || length == 4)
  36. {
  37. if (ch == '9') {
  38. strcpy_s(outnum, "NINE ");
  39. out = out + 5;
  40. }
  41. else
  42. if (ch == '8') {
  43. strcpy_s(outnum, "EIGHT ");
  44. out = out + 6;
  45. }
  46. else
  47. if (ch == '7') {
  48. strcpy_s(outnum, "SEVEN ");
  49. out = out + 6;
  50. }
  51. else
  52. if (ch == '6') {
  53. strcpy_s(outnum, "SIX ");
  54. out = out + 4;
  55. }
  56. else
  57. if (ch == '5') {
  58. strcpy_s(outnum, "FIVE ");
  59. out = out + 5;
  60. }
  61. else
  62. if (ch == '4') {
  63. strcpy_s(outnum, "FOUR ");
  64. out = out + 5;
  65. }
  66. else
  67. if (ch == '3') {
  68. strcpy_s(outnum, "THREE ");
  69. out = out + 6;
  70. }
  71. else
  72. if (ch == '2') {
  73. strcpy_s(outnum, "TWO ");
  74. out = out + 4;
  75. }
  76. else
  77. if (ch == '1') {
  78. strcpy_s(outnum, "ONE ");
  79. out = out + 4;
  80. }
  81. cout << outnum;
  82. }
  83. if ((length == 9 || length == 6)) {
  84. if ((length == 6 && ch != '0') || length == 9) {
  85. strcpy_s(outnum, "HUNDRED ");
  86. out = out + 8;
  87. }
  88. }
  89. if (length == 7) {
  90. strcpy_s(outnum, "THOUSAND ");
  91. out = out + 9;
  92. }
  93. else
  94. if (length == 8 || length == 5) {
  95. if (ch == '9') {
  96. strcpy_s(outnum, "NINETY ");
  97. out = out + 7;
  98. }
  99. else
  100. if (ch == '8') {
  101. strcpy_s(outnum, "EIGHTY ");
  102. out = out + 7;
  103. }
  104. else
  105. if (ch == '7') {
  106. strcpy_s(outnum, "SEVENTY ");
  107. out = out + 8;
  108. }
  109. else
  110. if (ch == '6') {
  111. strcpy_s(outnum, "SIXTY ");
  112. out = out + 6;
  113. }
  114. else
  115. if (ch == '5') {
  116. strcpy_s(outnum, "FIFTY ");
  117. out = out + 6;
  118. }
  119. else
  120. if (ch == '4') {
  121. strcpy_s(outnum, "FORTY ");
  122. out = out + 6;
  123. }
  124. else
  125. if (ch == '3') {
  126. strcpy_s(outnum, "THIRTY ");
  127. out = out + 7;
  128. }
  129. else
  130. if (ch == '2') {
  131. strcpy_s(outnum, "TWENTY ");
  132. out = out + 7;
  133. }
  134. else
  135. if (ch == '1') {
  136.  
  137. length = length - 1;
  138. i = i + 1;
  139. ch = buf[i];
  140. if (ch == '9') {
  141. strcpy_s(outnum, "NINETEEN ");
  142. out = out + 9;
  143. }
  144. else if (ch == '8') {
  145. strcpy_s(outnum, "EIGHTEEN ");
  146. out = out + 9;
  147. }
  148. else if (ch == '7') {
  149. strcpy_s(outnum, "SEVENTEEN ");
  150. out = out + 10;
  151. }
  152. else if (ch == '6') {
  153. strcpy_s(outnum, "SIXTEEN ");
  154. out = out + 8;
  155. }
  156. else if (ch == '5') {
  157. strcpy_s(outnum, "FIFTEEN ");
  158. out = out + 8;
  159. }
  160. else if (ch == '4') {
  161. strcpy_s(outnum, "FOURTEEN ");
  162. out = out + 9;
  163. }
  164. else if (ch == '3') {
  165. strcpy_s(outnum, "THIRTEEN ");
  166. out = out + 9;
  167. }
  168. else if (ch == '2') {
  169. strcpy_s(outnum, "TWELVE ");
  170. out = out + 7;
  171. }
  172. else if (ch == '1') {
  173. strcpy_s(outnum, "ELEVEN ");
  174. out = out + 7;
  175. }
  176. else if (ch == '0') {
  177. strcpy_s(outnum, "TEN ");
  178. out = out + 4;
  179. }
  180. cout << outnum;
  181. }
  182. if (length == 7) {
  183. strcpy_s(outnum, "THOUSAND ");
  184. out = out + 9;
  185. }
  186. }
  187. if (length == 3)
  188. strcpy_s(outnum, "");
  189. if (length == 2) {
  190. cout << "& ";
  191. out = out + 2;
  192. }
  193. if (length == 2 || length == 1) {
  194. cout << ch;
  195.  
  196. out = out + 1;
  197. }
  198. if (length == 1) {
  199. cout << " / 100 DOLLARS ";
  200. out = out + 11;
  201. }
  202. length = length - 1;
  203. i = i + 1;
  204. if (length != 3)
  205. cout << outnum;
  206. } while (length >= 1);
  207. output = 1;
  208. outleng = strlen(string);
  209. while (output <= (77 - out - outleng) && (length = 1))
  210. {
  211. cout << "*";
  212. output = output + 1;
  213. }
  214. cout << "*$";
  215. cout << string;
  216.  
  217. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: IsabellaButts on November 16, 2019

Many students are faced with this problem. You can always check the writing on the research paper writing service Paperial. It is cheap and very effective. Many students from my college already use this service to always have the best paperwork. I think you will be satisfied with the quality of the check.

You need to login to post a comment.