fork download
  1. //Matthew Santos CS1A Ch. 4, Pg. 220, #2
  2. /***********************************************
  3.  *
  4.  * CONVERT TO ROMAN NUMERALS
  5.  * _____________________________________________
  6.  * DESCRIPTION
  7.  * Converts a real number from 1-10 into its
  8.  * Roman Numeral.
  9.  * _____________________________________________
  10.  * INPUT
  11.  * num : number inputted
  12.  *
  13.  * OUTPUT
  14.  * Respective roman numeral
  15.  *
  16.  ***********************************************/
  17. #include <iostream>
  18. using namespace std;
  19.  
  20. int main() {
  21.  
  22. //Initialize values
  23. int num;
  24.  
  25. //Acquire input
  26. cin >> num;
  27.  
  28. //Determine which roman numeral
  29. switch (num){
  30. case 1:
  31. cout << "I";
  32. break;
  33. case 2:
  34. cout << "II";
  35. break;
  36. case 3:
  37. cout << "III";
  38. break;
  39. case 4:
  40. cout << "IV";
  41. break;
  42. case 5:
  43. cout << "V";
  44. break;
  45. case 6:
  46. cout << "VI";
  47. break;
  48. case 7:
  49. cout << "VII";
  50. break;
  51. case 8:
  52. cout << "VIII";
  53. break;
  54. case 9:
  55. cout << "IX";
  56. break;
  57. case 10:
  58. cout << "X";
  59. break;
  60. default:
  61. cout << "Enter a valid number (1-10)";
  62. break;
  63.  
  64.  
  65. }
  66.  
  67. return 0;
  68. }
Success #stdin #stdout 0.01s 5268KB
stdin
11
stdout
Enter a valid number (1-10)