Validation, and Upper case problems.

Wrote a program that will convert ROMAN nums into integers and integers into Roman nums.
The problems that I'm having is on how to make it so that the program tells the user that IIII is invalid (since 4 in ROMAN nums is IV)
Also when I use the program to convert ROMAN nums into integers, it only accepts lower case other wise it returns 0 and terminates.
Here is the code:

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
110
111
112
113
114
115
116
117
118
119
120
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <string>


using namespace std;

int rom_conv (string convert);
string int_conv (string numInteger);

int main()
{
	int choice = 0;
	
	cout << "|||||||||||WELCOME TO ROMAN NUMS CONVERTER|||||||||||||||\n"
		 << " 	Please Choose one of the following from this menu\n"
		 << " Press [1] if you wish to convert a ROMAN NUMERAL into an integer \n"
		 << " Press [2] if you wish to convert an Integer into a ROMAN NUMERAL \n"
		 << " Press [3] to quit" << endl;
	cin  >> choice;
	
	if (choice == 3)
	{
		cout << "\nThe program will now close";
		return 0;
	}
	
	else if	(choice == 1)
	{
		string input;
		int temp = 0;
		cout << " Please enter a ROMAN numeral that you wish to convert into an integer\n"
			 << " (please use lower cases)" << endl;
		cin >> input;
		temp = rom_conv (input);
		
		cout << "The ROMAN numeral that you input, in integer form is equivalent to this integer number: \n" 
			 << temp << endl;
		return 0;	 
		
	}
	
	else if (choice == 2)
	{
		string inputx;
		cout << " Please enter an INTEGER that you wish to convert into a ROMAN numeral\n";
		cin >> inputx;
		cout << "The INTEGER # " << inputx << endl;
		cout << " In ROMAN numerals is equivalent to: "  << int_conv(inputx);
		return 0; 	  
			 
	}
	
	system ("pause");
	return 0;
}

//////////////////////// Roman #'s conversion /////////////////////

int rom_conv (string convert)
{
	int final = 0;
	const int SizeArray = 7;
	char romannumerals [SizeArray] = {'I','V','X','L','C','D','M'};
	int integernums [SizeArray] = {1,5,10,50,100,500,1000};
	string input = convert;
	
	for (int x= 0; x < input.length(); x++)
	{
		input[x] = toupper(convert[x]); 
	}
	int* temp = new int [input.length()];
	for (int x = 0; x <input.length(); x++)
	{
	for (int y = 0; y <SizeArray; y++)
	{
	if (input[x] == romannumerals[y])
	{
	temp[x] = integernums [y];	
	}
	}
	}
	
	for (int x= 0;x< input.length () && (int)input.length() >1; x++)
	{
		int Currentvalue = temp[x], Newvalue = temp [x+1];
		if (Currentvalue < Newvalue && x < input.length()-1)
	{
	temp[x] *= -1;
	}
	final += temp[x];
	}
	return final;
	}

////////////////// INTEGER #'s Conversion ////////////////////
string int_conv (string numInteger)
{
	int number = atoi (numInteger.c_str());
	string inputx= "";
	const int SizeArray = 13;
	int integernumerals[SizeArray]={1000,900,500,400,100,90,50,40,10,9,5,4,1};
string romlist[SizeArray]={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"}; 
	int xnum= 0;
	
	while (number > 0)
	{
		if (number < integernumerals[xnum])
	{
		++xnum;
	}
	else
	{
		inputx += romlist[xnum];
		number -= integernumerals [xnum];
	}
	}
	return inputx;
}
The problems that I'm having is on how to make it so that the program tells the user that IIII is invalid (since 4 in ROMAN nums is IV)
You need to check the previous (if any) three roman letters. They must not equal the current

Also when I use the program to convert ROMAN nums into integers, it only accepts lower case other wise it returns 0 and terminates.
Um, no?
input[x] = toupper(convert[x]);

hmm... you can try using transform(word.begin(),word.end(),word.begin(),::toupper);
where word is the string. Note that you'll have to use <algorithm> to use this one.

Topic archived. No new replies allowed.