// write a program to read a string of characters
// that represent a Roman numberal and then convert
// to Arabic form ( an integer
// input from data file
#include <iostream> //keyboard I/O
#include <fstream> //external file streams
#include <conio.h> //getch()
#define in_file "data.txt"
usingnamespace std;
int main()
{
ifstream ins; //ins as output stream
//define variables
int total = 0,//total value of numbers
current = 0, //current character
previous = 5000; //previous character
char ch, //string to be read
M, D, C, L, X, I; //Roman numerals
//open files
ins.open(in_file);
while (!ins.eof())
{
ins.get(ch); //read ch from file
while (ch!='\n')
{
switch (ch)
{
case'M': current = 1000;
break;
case'D': current = 500;
break;
case'C': current = 100;
break;
case'L': current = 50;
break;
case'X': current = 10;
break;
case'V': current = 5;
break;
case'I': current = 1;
break;
} //end switch statement
if (previous >= current)
total += current;
else
total = total - (2*previous) + current;
previous = current;
ins.get(ch);
} //end inner while loop
cout << endl;
cout << " Your total is " << total << endl;
} //end outer while loop
ins.close();
getch();
}