Your input and conversion is a little confused. As there is no correlation between your input and output, and you are not initializing the char[] array in your class, you are getting a random number for output. (You are lucky it isn't crashing.)
A
char is not a
string -- a char holds a
single letter, where a string can hold many.
The user will input a
string, like:
IV
MMXIII
XIX
I presume your task is to take a string like that and convert it to an integer.
Or to take an integer and convert it into a string like that.
Hence, your main function should look something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
int main()
{
romanType r;
string input;
cout << "Please enter a Roman Numeral to convert to integer: ";
getline( cin, input );
r.setRomanNum( input );
if (!r.convertRomanNumToInt())
{
cout << "That was not a valid Roman Numeral.\n";
return 1;
}
cout << "The decimal equivalent is " << r.getInt() << ".\n";
return 0;
}
|
Were you given those methods to use, or did you create them yourself? I've modified them some... just to make life easier...
In the a
switch statement, you can combine labels for the same things...
1 2 3 4 5 6 7 8
|
switch (foo)
{
case 'M':
case 'm':
// stuff for M/m goes here
break;
...
}
|
You can safely make assumptions about the ordering, because the LARGEST values will always be listed FIRST, except for a couple of weird subtractive things, explained nicely here at Wikipedia:
http://en.wikipedia.org/wiki/Roman_numerals#Reading_Roman_numerals
Good luck! (You're going to be up all night.)