Given an integer n (input from the user), write a C++ program that determines the equivalent of n in the roman numerals. The user will provide a value of n greater than 0 and less than 4000.
this is what i have but it doesn't go up to 4000
Would you use the switch function in order to do this?
thanks.
#include <cstdlib>
#include <iostream>
usingnamespace std;
int main()
{
int n;
cout << "Enter n ";
cin >> n;
if ( n >= 10){
cout << "X";
n = n - 10;
}
if ( n >= 10){
cout << "X";
n = n - 10;
}
if ( n >= 10){
cout << "X";
n = n - 10;
}
/*
n is a number < 10
*/
if ( n == 9 ) {
cout << "IX";
n = n - 9;
}
/*
n is a number <= 8
*/
if ( n >= 5) {
cout << "V";
n = n - 5;
}
/*
n is a number <= 4
*/
if (n == 4) {
cout << "IV";
n = n - 4;
}
/*
n is a number 1,2,3
*/
if( n >= 1){
cout << "I";
n = n - 1;
}
if( n >= 1){
cout << "I";
n = n - 1;
}
if( n >= 1){
cout << "I";
n = n - 1;
}
//system("pause");
return 0;
}