Problem with roman numeral converter

Pages: 12
@giblit: Can you please show me what yours looked like when you ran it?
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include<iostream>

using namespace std;

class romanType
{
private:
	string romanNum;
	int decimalNum;
public:
	void setRoman(string romanString);
	void romanToDecimal();
	void printDecimal();
	void printRoman();
};

int main()
{
	romanType roman;
	string romanString;

	cout << "Please enter roman number: ";
	cin >> romanString;

	roman.setRoman(romanString);

}

void romanType::setRoman(string romanString)
{
	int previous = 1000;
	int sum = 0;

	for(int i = 0; i<romanString.length(); i++)
	{
		cout << romanString[i] << " ";
		if(romanString[i] == 'M')
		{
			sum = sum + 1000;
			if(previous<1000)
			{
				sum = sum - (2 * previous);
			}
			previous = 1000;
		}

		else if(romanString[i] == 'D')
		{
			sum = sum + 500;
			if(previous<500)
			{
				sum = sum - (2 * previous);
			}
			previous = 500;
		}

		else if(romanString[i] == 'C')
		{
			sum = sum + 100;
			if(previous<100)
			{
				sum = sum - (2 * previous);
			}
				previous = 100;
		}

			else if(romanString[i] == 'L')
		{
			sum = sum + 50;
			if(previous<50)
			{
				sum = sum - (2 * previous);
			}
				previous = 50;
		}

		else if(romanString[i] == 'X')
		{
			sum = sum + 10;
			if(previous<10)
			{
				sum = sum - (2 * previous);
			}
				previous = 10;
		}

			else if(romanString[i] == 'V')
		{
			sum = sum + 5;
			if(previous<5)
			{
				sum = sum - (2 * previous);
			}
				previous = 5;
		}

		else if(romanString[i] == 'I')
		{
			sum = sum + 1;
			previous = 1;
		}
	}

}
@gilbit: I don't understand, it keeps telling me 'unresolved external', but I swear everything is correct.
Well I don't know then because I do not get that error are you sure that is all of the code? Or I heard visual studios does that so maybe clean build or make a new project?
Last edited on
This is all the code? What ever happened to printDecimal, printRoman and romanToDecimal?
@gilbit: yeah, this is all the code. I don't know what the problem is but I'll figure it out, thanks though.
@Daleth: This is the whole code, I thought it should work, considering other people in my class ran it with just this and it was fine.
@manderson1

Why don't you get along with trying to fix the code with some of the suggestions we have made, rather than keep complaining about the existing code which doesn't work?

Also, if you have errors, then post them in full. But fix up your code first
Topic archived. No new replies allowed.
Pages: 12