fork download
  1. // Student Name : Saravanan Tirunelveli Kanthi
  2. // UCSD Student ID : U07612817
  3. // Email ID : tk.saravanan1@gmail.com
  4. // Course Name : C/C++ Programming I : Fundamental Programming Concepts
  5. // Course Number : CSE-40475
  6. // Section ID : 121615
  7. // Instructor Name : Raymond L. Mitchell, Jr., M.S.
  8. // Date : 04-23-2017
  9. // File Name : C1A3E3_main.cpp
  10. // Operating System : Windows 10
  11. // Compiler version : Visual C++ 14.0
  12. // Contents : Program to convert an integer value into words
  13.  
  14. #include <iostream>
  15. #include <cstdlib>
  16. using namespace std;
  17.  
  18. int main()
  19. {
  20. int usrInput;
  21.  
  22. cout << "Enter any integer value : ";
  23. cin >> usrInput;
  24. cout << endl << "\"" << usrInput << "\" in words is \"";
  25.  
  26. if(usrInput < 0)
  27. {
  28. cout << "minus ";
  29. usrInput *= -1;
  30. }
  31.  
  32. int dividend = usrInput;
  33. int divisor = 1;
  34. int loopIndex;
  35.  
  36. for(loopIndex = 0; ; loopIndex++)
  37. {
  38. if(dividend > 9)
  39. {
  40. divisor *= 10;
  41. dividend /= 10;
  42. }
  43. else
  44. {
  45. loopIndex++;
  46. break;
  47. }
  48. }
  49.  
  50. do
  51. {
  52. int msd = usrInput/divisor;
  53. switch(msd)
  54. {
  55. case 0:
  56. cout << "zero";
  57. break;
  58.  
  59. case 1:
  60. cout << "one";
  61. break;
  62.  
  63. case 2:
  64. cout << "two";
  65. break;
  66.  
  67. case 3:
  68. cout << "three";
  69. break;
  70.  
  71. case 4:
  72. cout << "four";
  73. break;
  74.  
  75. case 5:
  76. cout << "five";
  77. break;
  78.  
  79. case 6:
  80. cout << "six";
  81. break;
  82.  
  83. case 7:
  84. cout << "seven";
  85. break;
  86.  
  87. case 8:
  88. cout << "eight";
  89. break;
  90.  
  91. case 9:
  92. cout << "nine";
  93. break;
  94. }
  95.  
  96. usrInput = usrInput - (msd * divisor);
  97. divisor = divisor/10;
  98. loopIndex--;
  99.  
  100. }while(loopIndex != 0);
  101.  
  102. cout << "\"" << endl;
  103.  
  104. return EXIT_SUCCESS;
  105. }
  106.  
Success #stdin #stdout 0s 16064KB
stdin
-00012500
stdout
Enter any integer value : 
"-12500" in words is "minus onetwofivezerozero"