Something wrong with fstream

I wrote a program which reads a file containing roman numerals and translates it into integers. I am sure that my coding is done well but the only thing that seems messed up is that the program is not reading the file. Can you spot what I am doing wrong here?

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <string>
using namespace std;

const int I = 1, V = 5, X = 10,
L = 50, C = 100, D = 500,
M = 1000;


int get_data(ifstream &fin);
int conversion(char romchar);
char get_oper(ifstream &fin);
void calc(int val1, int val2, char oper, int &val3);
void print(int num);

int main()
{
int num1;
int num2;
int num3;
char operand;
ifstream fin;
fin.open("mp4romanletrdata.txt");

num1 = get_data(fin);
num2 = get_data(fin);
operand = get_oper(fin);
while (fin.is_open())
{
calc(num1, num2, operand, num3);

cout << "The first number is ";
print(num1);
cout << " ( " << num1 << " ). " << endl;

cout << "The second number is ";
print(num2);
cout << " ( " << num2 << " ). " << endl;

cout << "The operator is " << operand << endl;
cout << "The result is ";


print (num3);
cout << " ( " << num3 << " ). " << endl;
cout << "**************************************" << endl;
num1 = get_data(fin);
num2 = get_data(fin);
operand = get_oper(fin);
}
fin.close();
system("pause");



}


int get_data(ifstream &fin)
{
string num;
fin >> num;
int sum = 0;
for (int i = 0; i < num.length(); i++)
sum += conversion(num[i]);
return sum;


}


int conversion(char romchar)
{
if (romchar == 'M')
return M;
else if (romchar == 'D')
return D;
else if (romchar == 'C')
return C;
else if (romchar == 'L')
return L;
else if (romchar == 'X')
return X;
else if (romchar == 'V')
return V;
else
return I;
}

char get_oper(ifstream &fin)
{
char oper = 0;
fin >> oper;
return oper;
}

void calc(int val1, int val2, char oper, int &val3)
{
if (oper == '+')
val3 = val1 + val2;
else if (oper == '-')
val3 = val1 - val2;
else if (oper == '/')
val3 = val1 / val2;
else
val3 = val1 * val2;
}

void print(int num)
{
int j,i,v,x,l,c,d,m;
m = num / M;
num = num % M;
d = num / D;
num = num % D;
c = num / C;
num = num % C;
l = num / L;
num = num % L;
x = num / X;
num = num % X;
v = num / V;
num = num % V;
i = num / I;
num = num % I;

for (j=0;j<m;j++)
cout << "M";
for (j=0;j<d;j++)
cout << "D";
for (j=0;j<c;j++)
cout << "C";
for (j=0;j<l;j++)
cout << "L";
for (j=0;j<x;j++)
cout << "X";
for (j=0;j<v;j++)
cout << "V";
for (j=0;j<i;j++)
cout << "I";
}
Please use code tags: [code]Your code[/code]

This

fin.open("mp4romanletrdata.txt");

opens the file only when "mp4romanletrdata.txt" resides in the current path (you may not know what the current path is)

Use an absolute path like: "C:\\mydata\\mp4romanletrdata.txt"
Note that \ must be \\ in a c string
Thank you very much coder777. And yes, I will be sure to do that in the future. As you can tell, I am new on this forum.
Topic archived. No new replies allowed.