How would you solve this problem

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
  #include <cstdlib>
#include <iostream>

using namespace 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;
}
You need loops
Topic archived. No new replies allowed.