Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. /*
  2. File: main
  3. Author: Dr. Mark E. Lehr
  4. Created on October 17th, 2016, 9:35 PM
  5. Purpose:
  6. */
  7.  
  8. //System Libraries
  9. #include <iostream> //Input/Output objects
  10. using namespace std; //Name-space used in the System Library
  11.  
  12. //User Libraries
  13.  
  14. //Global Constants
  15.  
  16. //Function prototypes
  17.  
  18. //Execution Begins Here!
  19. int main(int argc, char** argv) {
  20. //Declaration of Variables
  21. unsigned short arabic;//An integer from [1000-3000]
  22. unsigned char n1000s,n100s,n10s,n1s;
  23.  
  24. //Input values
  25. do{
  26. cout<<"This program converts Arabic base 10 to Roman Numerals"<<endl;
  27. cout<<"Enter an integer from [1000-3000]"<<endl;
  28. cin>>arabic;
  29. }while(arabic<1000||arabic>3000);
  30.  
  31. //Process values -> Map inputs to Outputs
  32. //Thousands First
  33. n1000s=arabic/1000;
  34. switch(n1000s){
  35. case 3: cout<<"M";
  36. case 2: cout<<"M";
  37. case 1: cout<<"M";
  38. }
  39.  
  40. //100's next
  41. arabic%=1000;//Drop the 1000's
  42. n100s=arabic/100;
  43. switch(n100s){
  44. case 9: cout<<"CM";break;
  45. case 8: cout<<"DCCC";break;
  46. case 7: cout<<"DCC";break;
  47. case 6: cout<<"DC";break;
  48. case 5: cout<<"D";break;
  49. case 4: cout<<"CD";break;
  50. case 3: cout<<"C";
  51. case 2: cout<<"C";
  52. case 1: cout<<"C";
  53. }
  54.  
  55. //10's next
  56. arabic%=100;//Drop the 1000's
  57. n10s=arabic/10;
  58. switch(n10s){
  59. case 9: cout<<"XC";break;
  60. case 8: cout<<"LXXX";break;
  61. case 7: cout<<"LXX";break;
  62. case 6: cout<<"LX";break;
  63. case 5: cout<<"L";break;
  64. case 4: cout<<"XL";break;
  65. case 3: cout<<"X";
  66. case 2: cout<<"X";
  67. case 1: cout<<"X";
  68. }
  69.  
  70. //10's next
  71. arabic%=10;//Drop the 1000's
  72. n1s=arabic/1;
  73. switch(n1s){
  74. case 9: cout<<"IX";break;
  75. case 8: cout<<"VIII";break;
  76. case 7: cout<<"VII";break;
  77. case 6: cout<<"VI";break;
  78. case 5: cout<<"V";break;
  79. case 4: cout<<"IV";break;
  80. case 3: cout<<"I";
  81. case 2: cout<<"I";
  82. case 1: cout<<"I";
  83. }
  84.  
  85. //Exit Program
  86. return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement