i can't figure out my syntax error.

so my program works for the most part, but when I was testing it with cmixii it gave me 911 instead of 992. I don't know where i went wrong. please help.

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
105
106
107
108
109
if (Roman.length() > 1)
	{
		for (size_t i = 0; i < Roman.length(); i++)
		{
			ch = Roman[i];
			switch(ch)
			{
			case 'm':
			case 'M':
			{
				Deci = M;
				break;
			}
			case 'd':
			case 'D':
			{
				Deci = D;
				break;
			}
			case 'c':
			case 'C':
			{
				Deci = C;

				switch (Roman[i + 1])
				{
				case 'm':
				case 'M':
				{
					Deci = (M - C);
					i++;
					break;
				}
				case 'd':
				case 'D':
				{
					Deci = (D - C);
					i++;
					break;
				}
				
				}
				break;
			}
			case 'l':
			case 'L':
			{
				Deci = L;
				break;
			}
			case 'x':
			case 'X':
			{
				Deci = X;
				switch (Roman[i + 1])
				{
				case 'c':
				case 'C':
				{
					Deci = (C - X);
					i++;
					break;
				}
				case 'l':
				case 'L':
				{
					Deci = (L - X);
					i++;
					break;
				}
				}
				break;
			}
			case 'v':
			case 'V':
			{
				Deci = V;
				break;
			}
			case 'i':
			case 'I':
			{
				Deci = I;
				switch (Roman[i + 1])
				{
				case 'x':
				case 'X':
				{
					Deci = (X - I);
					i++;
					break;
				}
				case 'v':
				case 'V':
				{
					Deci = (V - I);
					i++;
					break;
				}
				}
				break;
			}
			}

			total = total + Deci;
		}
		setDecimal(total);
	}
cmixii does not make sense. cm is 900, but ix is 9 (not ninety). So you subtract one form 10, then add 2, so it is 11. You probably want cmxcii. If you want 911 you write cmxi
There is a C++ function that changes the case of a character, it is useful for switch statements like this, you can convert user input into the preferable case, such as this...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
char userInput;
std::cin >> userInput;

userInput = toupper( userInput ); // this changes input to UPPERCASE!

userInput = tolower( userInput ); //this changes input to LOWERCASE!

switch ( userInput )
{

   case A: blahblah;
             break;
   default: blahblah;
}

//This way, you need not to worry about having to test for both.
Last edited on
Topic archived. No new replies allowed.