fork download
  1. // Mariah Contreras CSC5 Chapter 4, P.222, #2
  2. //
  3. /* ************************************************************
  4.  *
  5.  * CONVERT POSOTIVE INTEGER INTO ROMAN NUMERAL
  6.  * ____________________________________________________________
  7.  * This program prompts the user to enter a number between 1
  8.  * and 10. Then converts it into a roman numeral
  9.  * compares the numbers.
  10.  * ____________________________________________________________
  11.  * INPUT
  12.  * posInt : positive whole number
  13.  * OUTPUT
  14.  * romanNum : Roman Numeral
  15.  **************************************************************/
  16. #include <iostream>
  17. #include <string>
  18. using namespace std;
  19.  
  20. int main ()
  21. {
  22. int posInt; //INPUT - Posotive Whole Number
  23. string romanNum; //OUTPUT - Roman Numeral
  24. //
  25. //Prompt User to Enter Number
  26. cout << "Enter a posotive whole number between 1 and 10";
  27. cin >> posInt;
  28. //
  29. //Convert to Roman Numeral
  30. switch (posInt)
  31. {
  32. case 1 :
  33. romanNum = "I";
  34. break;
  35. case 2 :
  36. romanNum = "II";
  37. break;
  38. case 3 :
  39. romanNum = "III";
  40. break;
  41. case 4 :
  42. romanNum = "IV";
  43. break;
  44. case 5 :
  45. romanNum = "V";
  46. break;
  47. case 6 :
  48. romanNum = "VI";
  49. break;
  50. case 7 :
  51. romanNum = "VII";
  52. break;
  53. case 8 :
  54. romanNum = "VIII";
  55. break;
  56. case 9 :
  57. romanNum = "IX";
  58. break;
  59. case 10 :
  60. romanNum = "X";
  61. break;
  62. default:
  63. romanNum = "invalid input";
  64. }
  65. cout << endl << posInt << " is equal to " << romanNum;
  66. cout << " in roman numerals";
  67. return 0;
  68. }
Success #stdin #stdout 0s 5360KB
stdin
2
stdout
Enter a posotive whole number between 1 and 10
2 is equal to II in roman numerals