roman numeral error validation

Hello. I am working on a little side project for school and have no idea where to start with the error validation if the user of the program enters a invalid roman numeral like LXXC. I also need to test if a lower value character precedes a higher value character. It can be at most 2 values lower. here is what I have got so far:
This is a header file required by my instructor:

#include <string> //including string to read in a string of roman chars
using namespace std;
class romanType //starting to define custom class romanType
{


private:
string str;
static char chRoman;
static int intRoman;

public:
void storeRoman();
void convertRoman();
void printRoman();
romanType();
};//end class definition


This is the class definitions of the class functions in a separate cpp file as per the request of my instructor:

#include <iostream>

#include "roman.h"//this is the header file defined above

using namespace std;

void romanType::convertRoman()//starting the function definition of the func convertRoman
{
//entering loop to check each spot in the string for a numeral
for (int i = 0; i < str.length(); i++)
{

if (chRoman == 'M')
{
intRoman=intRoman+1000;
}
else if (chRoman == 'D')
{
chRoman = cin.peek();
if(chRoman == 'M')
{
intRoman=intRoman-500;
}
else
{
intRoman=intRoman+500;
}
}

else if (chRoman == 'C')
{
chRoman = cin.peek();
if(chRoman == 'M' || chRoman == 'D')
{
intRoman=intRoman-100;
}
else
{
intRoman=intRoman+100;
}
}

else if (chRoman == 'L')
{
chRoman = cin.peek();
if(chRoman == 'M' || chRoman == 'D' || chRoman == 'C')
{
intRoman=intRoman-50;
}
else
{
intRoman=intRoman+50;
}
}

else if (chRoman == 'X')
{
chRoman = cin.peek();
if(chRoman == 'M' || chRoman == 'D' || chRoman == 'C' || chRoman == 'L')
{
intRoman=intRoman-10;
}
else
{
intRoman=intRoman+10;
}
}

else if (chRoman == 'V')
{
chRoman = cin.peek();
if(chRoman == 'M' || chRoman == 'D' || chRoman == 'C' || chRoman == 'L' || chRoman == 'X')
{ intRoman=intRoman-5;
}
else
{
intRoman=intRoman+5;
}
}

else if (chRoman == 'I')
{
chRoman = cin.peek();
if(chRoman == 'M' || chRoman == 'D' || chRoman == 'C' || chRoman == 'L' || chRoman == 'X' || chRoman == 'V')
{
intRoman=intRoman-1;
}
else
{
intRoman=intRoman+1;
}
}
else
{
cout<< "Invalid Data Entered!"<< endl;
cin.clear();
}

}//end for loop
}//ending convertRoman func

void romanType::printRoman()//starting printRoman Func
{
cout << "The Roman Value Was: "<< str << endl;
cout << "The Decimal Value Is: " << intRoman<< endl;
}//endiing func

romanType::romanType()//starting definition of constructor
{
chRoman='I';
intRoman=1;
}//ending constructor def

void romanType::storeRoman()//starting def of store roman func
{
char option;

do
{
cout<<"Enter the Roman Numeral in Capital letters (ex: CCXIX) : ";
cin >> str;
cout << endl;

romanType.convertRoman;//calling convertRoman Func
romanType.printRoman;//calling printRoman Func
cout << "Again? Y or y for yes or N or n for no";//asking if you want to iterate again
cin >> option;
cout << endl;
}while (option == 'Y'|| option =='y');
}//ending storeRoman func def

This is the main cpp file:
#include <iostream>

#include "roman.h"

using namespace std;

int main()//start of main function
{
romanType rtVar;//declaring a variable of the class type romanType

rtVar.storeRoman();//calling the store roman function

return 0;//ending main
}


Any help is greatly appreciated. Thanks in advance.
Last edited on
if you want to write comments you have to do this
1
2
3
code
code  //comment
code


or
1
2
3
code 
code /*comment*/ 
code
so do you want me to edit the code with comments?
i want you to use // or /**/ for stuff like

This is the class definitions of the class functions in a separate cpp file as per the request of my instructor:
I already know how to edit with comments. my question remains: do you want me to edit my code with comments?
using codetags and editing it in a way, where you can see start and end of functions would help
Last edited on
alright, the code is commented.
Topic archived. No new replies allowed.