Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1. /*
  2. * File: main.cpp
  3. * Author: James Rungsawang
  4. * Created on March 21st, 2019, 10:36 PM
  5. * Purpose: Menu Template
  6. */
  7.  
  8. //System Libraries
  9. #include <iostream> //Input/Output Library
  10. #include <cstdlib>
  11. #include <ctime>
  12. using namespace std;
  13.  
  14. //User Libraries
  15.  
  16. //Global Constants, no Global Variables are allowed
  17. //Math/Physics/Conversions/Higher Dimensions - i.e. PI, e, etc...
  18.  
  19. //Function Prototypes
  20.  
  21. //Execution Begins Here!
  22. int main(int argc, char** argv) {
  23. //Set the random number seed
  24. char choice,nProbs;
  25.  
  26. //Declare Variables
  27. nProbs='3';
  28.  
  29. do{
  30. //Present the menu to the user.
  31. cout<<"Choose from the following Menu"<<endl<<endl;
  32. cout<<"1 Roman Numeral Conversion"<<endl;
  33. cout<<"2 Problem 2"<<endl;
  34. cout<<"3 Problem 3"<<endl;
  35. cin>>choice;
  36.  
  37. //Select the problem to execute
  38. switch(choice){
  39. case '1': {
  40. //Set the random number seed
  41. srand(static_cast<unsigned int>(time(0)));
  42. //Declare Variables
  43. int decimal; //Decimal value between (1000-3000)
  44. string rnNum; //Roman numeral representation
  45.  
  46. //Initialize or input i.e. set variable values
  47. rnNum="";
  48. cout<<"Arabic to Roman numeral conversion."<<endl;
  49. cout<<"Input the integer to convert."<<endl; //Prompts user to enter an integer
  50. cin>>decimal; //Stores user input into variable
  51.  
  52.  
  53. //Map inputs -> outputs
  54. if(decimal<1000||decimal>3000){ //States if the input is between 1000 and 3000
  55. cout<<decimal<<" is Out of Range!";
  56. }
  57. else{
  58. //Determine number of 1000's
  59. int n1000s=decimal/1000%10; //Converts to roman numerals for the 1000s
  60. switch(n1000s){
  61. case 3:rnNum+='M';
  62. case 2:rnNum+='M';
  63. case 1:rnNum+='M';
  64. }
  65.  
  66. int n100s=decimal/100%10; //Converts to roman numerals for the 100s place
  67. switch(n100s){
  68. case 9:rnNum+="CM";break; //900 changes to CM
  69. case 8:rnNum+="DCCC";break; //800 changes to DCCC
  70. case 7:rnNum+="DCC";break; //700 changes to DCC
  71. case 6:rnNum+="DC";break; //600 changes to DC
  72. case 5:rnNum+="D";break; //500 changes to D
  73. case 4:rnNum+="CD";break; //400 changes to CD
  74. case 3:rnNum+="C";break; //300 changes to C
  75. case 2:rnNum+="C";break; //200 changes to C
  76. case 1:rnNum+="C";break; //100 changes to C
  77.  
  78. }
  79.  
  80. int n10s=decimal/10%10; //Converts to roman numerals for the 10s place
  81. switch(n10s){
  82. case 9:rnNum+="XC";break; //90 changes to XC
  83. case 8:rnNum+="LXXX";break; //80 changes to LXXXX
  84. case 7:rnNum+="LXX";break; //70 changes to LXX
  85. case 6:rnNum+="LX";break; //60 changes to LX
  86. case 5:rnNum+="L";break; //50 changes to L
  87. case 4:rnNum+="XL";break; //40 changes to XL
  88. case 3:rnNum+="X";break; //30 changes to X
  89. case 2:rnNum+="X";break; //20 changes to X
  90. case 1:rnNum+="X";break; //10 changes to X
  91. }
  92. int n1s=decimal/1%10; //Converts to roman numerals for the 1s place
  93. switch(n1s){
  94. case 9:rnNum+="IX";break; //9 changes to IX
  95. case 8:rnNum+="VIII";break; //8 changes to VIII
  96. case 7:rnNum+="VII";break; //7 changes to VII
  97. case 6:rnNum+="VI";break; //6 changes to VI
  98. case 5:rnNum+="V";break; //5 changes to V
  99. case 4:rnNum+="IV";break; //4 changes to V
  100. case 3:rnNum+="III";break; //3 changes to III
  101. case 2:rnNum+="II";break; //2 changes to II
  102. case 1:rnNum+="I";break; //1 changes to I
  103.  
  104. }
  105. cout<<decimal<<" is equal to "<<rnNum<<endl; //Prints what roman numeral the decimal is equal to
  106. break;
  107. }
  108.  
  109. }
  110. case '2': {
  111. cout<<"Place problem 2 here"<<endl<<endl;
  112. break;
  113. }
  114. case '3': {
  115. cout<<"Place problem 3 here"<<endl<<endl;
  116. break;
  117. }
  118. default:
  119. cout<<"Exiting Menu"<<endl<<endl;
  120. }
  121. }while(choice<=nProbs);
  122.  
  123.  
  124.  
  125.  
  126. //Display the outputs
  127.  
  128. //Exit stage right or left!
  129. return 0;
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement