Hello,
This is my program here...I want to make it read from a textfile and displayed in this way
Number : 1
Roman Numeral : I
Number : 2
Roman Numeral : II
My textfile is in this form:
1
2
but i still unable to solve it...is something to do with the highlight part. Please guide me along.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream fin;
string romNum;
//string filename;
int araNum;
fin.open("number.txt");
if (!fin.good())
{
cout << "File not found" << endl;
return 1;
}
while(!fin.eof())
{
[B] fin >> romNum >> araNum ;
cout << "Number : " << romNum << endl;
cout << "Roman Numeral : " << araNum << endl << endl;[/B]
while (araNum >=1000)
{
cout <<"M";
araNum -= 1000; //to stop infinity of while loop
}
while (araNum >=900)
{
cout <<"CM";
araNum -= 900;
}
while (araNum >=500)
{
cout <<"D";
araNum -= 500;
}
while (araNum >=400)
{
cout <<"CD";
araNum -= 400;
}
while (araNum >=100)
{
cout <<"C";
araNum -= 100;
}
while (araNum >=90)
{
cout <<"XC";
araNum -= 90;
}
while (araNum >=50)
{
cout <<"L";
araNum -= 50;
}
while (araNum >=40)
{
cout <<"XL";
araNum -= 40;
}
while (araNum >=10)
{
cout <<"X";
araNum -= 10;
}
while (araNum >=9)
{
cout <<"IX";
araNum -= 9;
}
while (araNum >=5)
{
cout <<"V";
araNum -= 5;
}
while (araNum >=4)
{
cout <<"IV";
araNum -= 4;
}
while (araNum >=1)
{
cout <<"I";
araNum -= 1;
}
}
}