fork download
  1. //Zachary Abdollahi CS1A Chapter 4, P. 220, #2
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * CONVERT NUMBERS TO ROMAN NUMERALS
  6.  *
  7.  *______________________________________________________________________________
  8.  * This program asks the user to enter a number from 1 to 10 and uses a switch
  9.  * statement to display the Roman numeral version of that number. Input is
  10.  * validated so numbers less than 1 or greater than 10 are not accepted.
  11.  *
  12.  * INPUT
  13.  * number : Number entered by user (1-10)
  14.  *
  15.  * OUTPUT
  16.  * Roman numeral equivalent of number, printed to screen
  17.  *
  18.  ******************************************************************************/
  19. #include <iostream>
  20. using namespace std;
  21. int main()
  22. {
  23. int number; //INPUT - Number entered by user (1-10)
  24.  
  25. // Get input from the user, with validation
  26. cout << "Enter a number from 1 to 10: ";
  27. cin >> number;
  28.  
  29. while (number < 1 || number > 10)
  30. {
  31. cout << "Invalid number. Please enter a number from 1 to 10: ";
  32. cin >> number;
  33. }
  34.  
  35. // Use a switch statement to display the Roman numeral
  36. switch (number)
  37. {
  38. case 1:
  39. cout << "The Roman numeral is I " << endl;
  40. break;
  41. case 2:
  42. cout << "The Roman numeral is II" << endl;
  43. break;
  44. case 3:
  45. cout << "The Roman numeral is III" << endl;
  46. break;
  47. case 4:
  48. cout << "The Roman numeral is IV" << endl;
  49. break;
  50. case 5:
  51. cout << "The Roman numeral is V" << endl;
  52. break;
  53. case 6:
  54. cout << "The Roman numeral is VI" << endl;
  55. break;
  56. case 7:
  57. cout << "The Roman numeral is VII" << endl;
  58. break;
  59. case 8:
  60. cout << "The Roman numeral is VIII" << endl;
  61. break;
  62. case 9:
  63. cout << "The Roman numeral is IX" << endl;
  64. break;
  65. case 10:
  66. cout << "The Roman numeral is X" << endl;
  67. break;
  68. }
  69.  
  70. return 0;
  71. }
Success #stdin #stdout 0.01s 5320KB
stdin
6

stdout
Enter a number from 1 to 10: The Roman numeral is VI